-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Python Business Intelligence Cookbook
By :
Along with CSV, JSON is another commonly found format for datasets, especially when extracting data from web APIs.
To create a Pandas DataFrame from a JSON file, first import the Python libraries that you need:
import pandas as pd
Next, define a variable for the JSON file and enter the full path to the file:
customer_json_file = 'customer_data.json'
Next, create a DataFrame from the JSON file using the read_json() method provided by Pandas. Note that the dates in our JSON file are stored in the ISO format, so we're going to tell the read_json() method to convert dates:
customers_json = pd.read_json(customer_json_file, convert_dates=True)
Finally, use the head() command to see the top five rows of data:
customers_json.head()
After importing Pandas and defining a variable for the full path to our JSON file, we use the read_json() method provided by Pandas to create a DataFrame from our JSON file.
read_json() takes a number of...
Change the font size
Change margin width
Change background colour