0
0
Pandasdata~10 mins

Reading CSV files with read_csv in Pandas - 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 a CSV file named 'data.csv' into a DataFrame.

Pandas
import pandas as pd
df = pd.[1]('data.csv')
Drag options to blanks, or click blank then click option'
Aread_table
Bread_excel
Cread_json
Dread_csv
Attempts:
3 left
💡 Hint
Common Mistakes
Using read_excel instead of read_csv
Using read_json which is for JSON files
Using read_table which expects tab-separated files
2fill in blank
medium

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

Pandas
import pandas as pd
df = pd.read_csv('data.csv', [1]=5)
Drag options to blanks, or click blank then click option'
Anrows
Brows
Chead
Dlimit
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'head' which is a method on DataFrames, not a parameter
Using 'rows' or 'limit' which are not valid parameters
3fill in blank
hard

Fix the error in the code to read a CSV file with a semicolon separator.

Pandas
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 when the file uses semicolons
Using pipe or colon which are different delimiters
4fill in blank
hard

Fill both blanks to read 'data.csv' using only columns 'Name' and 'Age'.

Pandas
import pandas as pd
df = pd.read_csv('data.csv', usecols=[1], dtype=[2])
Drag options to blanks, or click blank then click option'
A['Name', 'Age']
B{'Name': str, 'Age': int}
C['Name', 'Salary']
D{'Name': int, 'Age': str}
Attempts:
3 left
💡 Hint
Common Mistakes
Selecting wrong columns in usecols
Mixing up data types in dtype
5fill in blank
hard

Fill all three blanks to read 'data.csv' skipping the first row, setting index to 'ID', and parsing dates in 'Date' column.

Pandas
import pandas as pd
df = pd.read_csv('data.csv', skiprows=[1], index_col=[2], parse_dates=[3])
Drag options to blanks, or click blank then click option'
A1
B'ID'
C['Date']
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Not skipping the header row properly
Using wrong index column name
Not parsing dates correctly