Pandas convert JSON string to Dataframe - Python
You can also do it this way to get the exact format:
pd.DataFrame(my_json).T.rename_axis(columns='Date') Date open high low close volume2017-01-03 214.86 220.33 210.96 216.99 5923254.02017-12-29 316.18 316.41 310.00 311.35 3777155.0
You can also read directly from the data to get the format with the missing date:
pd.DataFrame.from_dict(my_json, orient='index').rename_axis(columns='Date') Date open high low close volume2017-01-03 214.86 220.33 210.96 216.99 59232542017-12-29 316.18 316.41 310.00 311.35 3777155
I assume my_json
is dictionary. I.e, it it not in string format
pd.DataFrame.from_dict(my_json, orient='index').rename_axis('date').reset_index()Out[632]: date open high low close volume0 2017-01-03 214.86 220.33 210.96 216.99 59232541 2017-12-29 316.18 316.41 310.00 311.35 3777155
If my_json
in string format, you need call ast.iteral_eval
to convert to dictionary before processing
import astd = ast.literal_eval(my_json)pd.DataFrame.from_dict(d, orient='index').rename_axis('date').reset_index()