A complete working example
First I save the data you posted in a json file:
import json
import pandas as pd
json_data = {"biennials": 522004, "lb915": 116290, "shatzky": 127647,
"woode": 174106, "damfunk": 133206, "nualart": 153444,
"hatefillot": 164111, "missionborn": 261765,
"yeardescribed": 161075, "theoryhe": 521685}
save_fpath = '/content/sample_file.json'
with open(save_fpath, 'w') as f:
json.dump(json_data, f)
Then, using the method proposed by obiradaniel, it's possible to obtain a pandas dataframe through this code:
sample_df = pd.read_json(save_fpath, lines=True).T.reset_index()
sample_df.columns = ['col_1', 'col_2']
sample_df
Basically, the keys of the json_data
dictionary are transformed into column names using lines=True
. For this reason I then transpose the dataframe (column names become index names) and then reset the index. Finally, new column names are assigned.
It's possible to skip the transposition step using the orient
argument. In this way, the keys of the json_data
dict are read from the beginning as index names. Here is an example using that:
sample_df = pd.read_json(save_fpath, orient='index').reset_index()
sample_df.columns = ['col_1', 'col_2']
sample_df
In both ways, the resulting dataframe is the following:
|
col_1 |
col_2 |
0 |
biennials |
522004 |
1 |
lb915 |
116290 |
2 |
shatzky |
127647 |
3 |
woode |
174106 |
4 |
damfunk |
133206 |
5 |
nualart |
153444 |
6 |
hatefillot |
164111 |
7 |
missionborn |
261765 |
8 |
yeardescribed |
161075 |
9 |
theoryhe |
521685 |