Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to read a JSON file into a pandas DataFrame.
Pandas
import pandas as pd df = pd.[1]('data.json')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using read_csv instead of read_json
Forgetting to import pandas
Using read_excel for JSON files
✗ Incorrect
The read_json function reads JSON files into a pandas DataFrame.
2fill in blank
mediumComplete the code to read JSON data from a string using pandas.
Pandas
import pandas as pd json_str = '{"name": ["Alice", "Bob"], "age": [25, 30]}' df = pd.read_json([1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a filename string instead of the JSON string variable
Not using quotes correctly around the JSON string
Using a variable name that does not exist
✗ Incorrect
To read JSON from a string, pass the string variable to read_json.
3fill in blank
hardFix the error in the code to correctly read a JSON file with pandas.
Pandas
import pandas as pd df = pd.read_json('data.json', [1]='records')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect parameter names like 'format' or 'style'
Misspelling 'orient'
Passing wrong values to the parameter
✗ Incorrect
The orient parameter specifies the expected JSON string format.
4fill in blank
hardFill both blanks to create a DataFrame from JSON data and display the first rows.
Pandas
import pandas as pd json_path = 'data.json' df = pd.[1](json_path) print(df.[2]())
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using read_csv instead of read_json
Using tail() instead of head() to preview data
Forgetting parentheses after head or tail
✗ Incorrect
Use read_json to load JSON data and head() to show the first rows.
5fill in blank
hardFill all three blanks to read JSON data, select a column, and convert it to a list.
Pandas
import pandas as pd df = pd.[1]('data.json') names = df[[2]].[3]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using read_csv instead of read_json
Selecting the wrong column name
Using to_list() instead of tolist()
✗ Incorrect
Read JSON with read_json, select the 'name' column, and convert it to a list with tolist().