0
0
Pandasdata~5 mins

read_csv parameters (sep, header, index_col) in Pandas - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the sep parameter do in pandas.read_csv()?
The sep parameter tells pandas which character separates the columns in the CSV file. For example, sep=',' means columns are separated by commas.
Click to reveal answer
beginner
What is the purpose of the header parameter in read_csv()?
The header parameter tells pandas which row to use as the column names. For example, header=0 means the first row is the header. If header=None, pandas will not treat any row as header and will assign default column names.
Click to reveal answer
beginner
How does the index_col parameter affect the DataFrame when reading a CSV?
The index_col parameter tells pandas which column(s) to use as the row labels (index) of the DataFrame. For example, index_col=0 uses the first column as the index.
Click to reveal answer
beginner
If a CSV file uses semicolons (;) to separate columns, how should you read it with pandas?
You should set sep=';' in read_csv() to tell pandas to split columns at semicolons.
Click to reveal answer
beginner
What happens if you set header=None when reading a CSV file?
Pandas will not treat any row as the header. It will assign default column names like 0, 1, 2, ... and treat all rows as data.
Click to reveal answer
Which parameter in read_csv() specifies the character that separates columns?
Asep
Bheader
Cindex_col
Ddelimiter
What does header=0 mean when reading a CSV file?
ASkip the first row
BNo header row
CUse the first column as index
DUse the first row as column names
If you want the first column of a CSV to be the DataFrame index, which parameter do you use?
Aheader=0
Bindex_col=0
Csep=','
Dusecols=0
How do you read a CSV file with no header row?
Aheader=None
Bheader=0
Cindex_col=None
Dsep=None
Which of these is NOT a valid use of read_csv() parameters?
Aindex_col='Name' to use column named 'Name' as index
Bheader=1 to use second row as header
Cheader='first' to use first row as header
Dsep=';' to read semicolon-separated files
Explain how the sep, header, and index_col parameters work in pandas.read_csv().
Think about how pandas knows where columns start and end, which row has names, and which column labels rows.
You got /3 concepts.
    Describe a situation where you would set header=None and index_col=0 when reading a CSV file.
    Imagine a CSV with data only, no column names, but the first column is special for row labels.
    You got /4 concepts.