You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
And it cannot be retrieved properly with current API connector.
I have added below code to fix the problem, but the iterator make the whole process quite slow...
try:
df = pd.DataFrame(json.loads(r.text))
df = df.set_index('t')
df.index = pd.to_datetime(df.index, unit='s')
df = df.sort_index()
s = pd.DataFrame()
for r, c in df.iterrows():
for k, v in c['o'].items():
s.loc[r, k] = v
return s
except Exception as e:
print(e)
Here is the modified version I am using to allow pulling data with multiple columns.
This does not iterate over rows so should be faster.
Note I have also changed the column names to only include metric and not indicator.metric.
try:
df = pd.DataFrame(json.loads(r.text))
df = df.set_index('t')
df.index = pd.to_datetime(df.index, unit='s')
df = df.sort_index()
if 'v' in df:
s = df.v
# s.name = '_'.join(url.split('/')[-2:])
s.name = url.split('/')[-1]
return pd.DataFrame(s)
else: # 'o' contains json object of multiple columns
index = df.index
df = pd.json_normalize(df.o)
df.index = index
col_name_prefix = url.split('/')[-1]
df.columns = [f'{col_name_prefix}.{col}' for col in df.columns]
return df
except Exception as e:
print(e)
Activity
neilsummers commentedon Jul 1, 2021
Here is the modified version I am using to allow pulling data with multiple columns.
This does not iterate over rows so should be faster.
Note I have also changed the column names to only include
metricand notindicator.metric.