0
0
Pandasdata~10 mins

Why data I/O matters in Pandas - Test Your Understanding

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 into a pandas DataFrame.

Pandas
import pandas as pd
data = pd.[1]('data.csv')
Drag options to blanks, or click blank then click option'
Aread_csv
Bto_csv
Cread_excel
Dto_excel
Attempts:
3 left
💡 Hint
Common Mistakes
Using to_csv instead of read_csv
Using read_excel for CSV files
2fill in blank
medium

Complete the code to save a DataFrame to an Excel file.

Pandas
import pandas as pd
df = pd.DataFrame({'A': [1, 2]})
df.[1]('output.xlsx')
Drag options to blanks, or click blank then click option'
Aread_excel
Bto_excel
Cread_csv
Dto_csv
Attempts:
3 left
💡 Hint
Common Mistakes
Using read_excel instead of to_excel
Using to_csv for Excel files
3fill in blank
hard

Fix the error in the code to correctly read a JSON file into a DataFrame.

Pandas
import pandas as pd
data = pd.[1]('data.json')
Drag options to blanks, or click blank then click option'
Ato_json
Bread_csv
Cread_json
Dto_csv
Attempts:
3 left
💡 Hint
Common Mistakes
Using to_json instead of read_json
Using read_csv for JSON files
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths only if the length is greater than 3.

Pandas
words = ['apple', 'bat', 'carrot', 'dog']
lengths = {word: [1] for word in words if [2]
Drag options to blanks, or click blank then click option'
Alen(word)
Bword
Clen(word) > 3
Dword > 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using word instead of len(word) for the value
Using word > 3 which compares strings to numbers
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths only if length is less than 5.

Pandas
words = ['apple', 'bat', 'carrot', 'dog']
result = { [1]: [2] for w in words if [3] }
Drag options to blanks, or click blank then click option'
Aw.upper()
Blen(w)
Clen(w) < 5
Dw.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using w.lower() instead of w.upper()
Using len(w) > 5 instead of less than 5