Complete the code to read a JSON file into a DataFrame.
import pandas as pd df = pd.[1]('data.json') print(df.head())
The read_json function reads JSON files into a DataFrame.
Complete the code to read a JSON string into a DataFrame.
import pandas as pd json_str = '{"name": ["Alice", "Bob"], "age": [25, 30]}' df = pd.[1](json_str) print(df)
read_json can read JSON strings directly into a DataFrame.
Fix the error in the code to correctly read a JSON file with lines.
import pandas as pd df = pd.read_json('data.json', [1]=True) print(df.head())
The lines=True parameter tells pandas to read a JSON file where each line is a separate JSON object.
Fill both blanks to read a JSON file and set the correct orientation.
import pandas as pd df = pd.read_json('data.json', [1]='[2]') print(df.head())
The orient='records' parameter tells pandas the JSON is a list of records (dictionaries).
Fill all three blanks to read a JSON string with lines and convert it to a DataFrame.
import pandas as pd json_str = '{"name": "Alice", "age": 25}\n{"name": "Bob", "age": 30}' df = pd.read_json([1], [2]=[3]) print(df)
To read a JSON string with multiple JSON objects separated by lines, use lines=True and pass the string variable.