Load nested json with pandas

Load nested json with pandas read nested json with pandas

environment

Google Corab

Event

With pandas

import pandas as pd
pd.read_json('file.json')

When you do

index title content
1 aaa {"col1": "a", "col2": "aa"...
2 bbb {"col1": "b", "col2": "bb"...

Suppose you have a json file that looks like this: (It is a form in which json format character strings are nested and stored in content.)

this,

col1 col2
a aa
b bb

I wanted to read it.

I searched a little with normalize or flatten and found that pd.json_normalize ('file.json') looked like that, so when I tried using it, I got angry with ʻAttribute Error:'str' object has no attribute'values'`. I did.

Solution

After trial and error,

import pandas as pd
df = pd.read_json('file.json')
df = pd.DataFrame(df.content.to_list())

I read it correctly in, so I will write it as an article.

Recommended Posts

Load nested json with pandas
[Pandas] Save DataFrame as JSON, load JSON as DataFrame
Load csv with duplicate columns in pandas
Load csv with pandas and play with Index
Quickly visualize with Pandas
[Python] Use JSON with Python
Processing datasets with pandas (1)
Bootstrap sampling with Pandas
Convert 202003 to 2020-03 with pandas
Processing datasets with pandas (2)
Merge datasets with pandas
Learn Pandas with Cheminformatics
json parse with gdb
Data visualization with pandas
Data manipulation with Pandas!
Shuffle data with pandas
LOAD DATA with PyMysql
How to convert JSON file to CSV file with Python Pandas
[Linux] [Python] [Pandas] Load Microsoft Access database (* .mdb) with Pandas
[Memo] Load csv of s3 into pandas with boto3
Read csv with python pandas
POST json with Python3 script
[Python] Change dtype with pandas
Standardize by group with pandas
Load test Websocket with Locust
Format json with Vim (with python)
Handle JSON files with Matlab
Prevent omissions with pandas print
Data processing tips with Pandas
Read json data with python
[Python3] Save the mean and covariance matrix in json with pandas
Save & load data with joblib, pickle
Load Django modules with an interpreter
Extract the maximum value with pandas.
Load multiple JavaScript files with PyWebView
Dynamically load json type in python
Versatile data plotting with pandas + matplotlib
JSON encoding and decoding with python
[Python] Join two tables with pandas
Dynamically create new dataframes with pandas
Extract specific multiple columns with pandas
1. Statistics learned with Python 1-1. Basic statistics (Pandas)
Load gif images with Python + OpenCV
Convenient analysis with Pandas + Jupyter notebook
Draw a graph with pandas + XlsxWriter
Manipulating strings with pandas group by
Bulk Insert Pandas DataFrame with psycopg2
I want to do ○○ with Pandas
Create an age group with pandas
Merge JSON format data with Ansible
Excel aggregation with Python pandas Part 1
[Python] Format when to_csv with pandas
Feature generation with pandas group by
Handle various date formats with pandas