0
0
Pandasdata~10 mins

Exporting results to multiple formats 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 export the DataFrame to a CSV file named 'data.csv'.

Pandas
df.to_csv([1])
Drag options to blanks, or click blank then click option'
A'data.csv'
B'table.xlsx'
C'output.json'
D'data.txt'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a file extension other than '.csv' for CSV export.
Forgetting quotes around the filename.
2fill in blank
medium

Complete the code to export the DataFrame to an Excel file named 'report.xlsx'.

Pandas
df.to_excel([1])
Drag options to blanks, or click blank then click option'
A'report.json'
B'report.csv'
C'report.xlsx'
D'report.txt'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '.csv' extension with to_excel.
Not using quotes around the filename.
3fill in blank
hard

Fix the error in the code to export the DataFrame to a JSON file named 'data.json'.

Pandas
df.[1]('data.json')
Drag options to blanks, or click blank then click option'
Ato_json
Bto_csv
Cto_excel
Dsave_json
Attempts:
3 left
💡 Hint
Common Mistakes
Using to_csv or to_excel instead of to_json.
Using a non-existent method like save_json.
4fill in blank
hard

Fill both blanks to export only the 'Name' and 'Age' columns to a CSV file named 'subset.csv'.

Pandas
df.loc[:, [[1], [2]]].to_csv('subset.csv', index=False)
Drag options to blanks, or click blank then click option'
A'Name'
B'Age'
C'Salary'
D'Department'
Attempts:
3 left
💡 Hint
Common Mistakes
Selecting wrong columns.
Forgetting quotes around column names.
5fill in blank
hard

Fill all three blanks to export rows where 'Score' is greater than 80 to a JSON file named 'high_scores.json'.

Pandas
df_filtered = df[df[[1]] [2] [3]]
df_filtered.to_json('high_scores.json')
Drag options to blanks, or click blank then click option'
A'Score'
B>
C80
D'Age'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong column name.
Using wrong comparison operator.
Putting number 80 in quotes.