0
0
Data Analysis Pythondata~10 mins

Reading CSV files (read_csv) in Data Analysis Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to read the CSV file 'data.csv' into a DataFrame named df.

Data Analysis Python
import pandas as pd
df = pd.[1]('data.csv')
Drag options to blanks, or click blank then click option'
Ato_csv
Bread_excel
Cread_csv
Dread_json
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'read_excel' instead of 'read_csv'.
Using 'to_csv' which is for saving, not reading.
2fill in blank
medium

Complete the code to read 'data.csv' but only load the first 5 rows.

Data Analysis Python
import pandas as pd
df = pd.read_csv('data.csv', [1]=5)
Drag options to blanks, or click blank then click option'
Ahead
Bnrows
Crows
Dlimit
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'head' which is a DataFrame method, not a read_csv parameter.
Using 'limit' which is not a valid parameter.
3fill in blank
hard

Fix the error in the code to read 'data.csv' with a semicolon separator.

Data Analysis Python
import pandas as pd
df = pd.read_csv('data.csv', sep=[1])
Drag options to blanks, or click blank then click option'
A;
B,
C|
D:
Attempts:
3 left
💡 Hint
Common Mistakes
Using comma ',' which is default but incorrect here.
Using other characters like '|' or ':'.
4fill in blank
hard

Fill both blanks to read 'data.csv' skipping the first row and using tab as separator.

Data Analysis Python
import pandas as pd
df = pd.read_csv('data.csv', skiprows=[1], sep=[2])
Drag options to blanks, or click blank then click option'
A1
B0
C,
D\t
Attempts:
3 left
💡 Hint
Common Mistakes
Using skiprows=0 which does not skip any rows.
Using comma ',' as separator instead of tab.
5fill in blank
hard

Fill both blanks to read 'data.csv' with no header, assign column names, and use comma separator.

Data Analysis Python
import pandas as pd
cols = ['Name', 'Age', 'City']
df = pd.read_csv('data.csv', header=[1], names=[2], sep=,)
Drag options to blanks, or click blank then click option'
ANone
Bcols
C,
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using header=0 which assumes first row is header.
Not passing column names when header is None.
Using wrong separator.