import pandas as pd
import json
data = {
'locationId':123546987,
'parameters':[
{
'parameterId':'11',
'unitId':'81',
'customParameter':False,
'readings':[
{
'timestamp':1538957700,
'value':2306.078
},
{
'timestamp':1538959500,
'value':2305.892
},
{
'timestamp':1538961300,
'value':2305.981
}
]
},
{
'parameterId':'1',
'unitId':'1',
'customParameter':False,
'readings':[
{
'timestamp':1538957700,
'value':25.575
},
{
'timestamp':1538959500,
'value':25.572
},
{
'timestamp':1538961300,
'value':25.575
}
]
}
]
}
val = json.loads(json.dumps(data))
val1 = val['parameters']
#val2 = [{'timestamp': 1538957700, 'value': 2306.078}, {'timestamp': 1538959500, 'value': 2305.892}, {'timestamp': 1538961300, 'value': 2305.981}]
val2 = val1['readings']
df = pd.DataFrame(val1).set_index('parameterId')
print(df)
df2 = pd.DataFrame(val2)
print(df2)
val = json.loads(json.dumps(data))
val = pd.DataFrame(val)
def getReadings(dict):
d = pd.DataFrame(dict['readings'], columns=['parameterId','customParameter','timestamp','value','unitId'])
d['parameterId'] = dict['parameterId']
d['customParameter'] = dict['customParameter']
d['unitId'] = dict['unitId']
return d
df = pd.DataFrame()
for i in range(len(val)):
df1 = getReadings(val.iloc[i,1])
df = df.append(df1)
print(df)
import pandas as pd
import json
data = {
'locationId':123546987,
'parameters':[
{
'parameterId':'11',
'unitId':'81',
'customParameter':False,
'readings':[
{
'timestamp':1538957700,
'value':2306.078
},
{
'timestamp':1538959500,
'value':2305.892
},
{
'timestamp':1538961300,
'value':2305.981
}
]
},
{
'parameterId':'1',
'unitId':'1',
'customParameter':False,
'readings':[
{
'timestamp':1538957700,
'value':25.575
},
{
'timestamp':1538959500,
'value':25.572
},
{
'timestamp':1538961300,
'value':25.575
}
]
}
]
}
print(data)
val = json.loads(json.dumps(data))
val = pd.DataFrame(val)
print(val)
def getReadings(dict):
d = pd.DataFrame(dict['readings'])
d['unitId'] = dict['unitId']
d['parameterId'] = dict['parameterId']
return d
df = pd.DataFrame()
for i in range(len(val)):
df1 = getReadings(val.iloc[i,1])
df1['locationId'] = val.iloc[i,0]
df1['customParameter'] = 'False'
df = df.append(df1)
df = df[['parameterId','customParameter','timestamp','value','unitId']]
print(df)
Open in new window