9951 explained code solutions for 126 technologies


python-pandasHow to create dataframe from JSON


import pandas as pd
json = '''{"Phone":["ip5","ip6","ip8","sms","xi"],"Price":[204,304,404,405,305],"Color":["red","red","gray","black","red"]}'''
df = pd.read_json(json)ctrl + c
import pandas as pd

load Pandas module

.read_json(

will parse specified JSON string and create dataframe


Usage example

import pandas as pd
jsonStr = '''{"Phone":["ip5","ip6","ip8","sms","xi"],"Price":[204,304,404,405,305],"Color":["red","red","gray","black","red"]}'''
df = pd.read_json(jsonStr)
print(df)
output
  Phone  Price  Color
0   ip5    204    red
1   ip6    304    red
2   ip8    404   gray
3   sms    405  black
4    xi    305    red