Open TurtleJelly opened 3 years ago
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)
Hi Team Glassnode,
When retrieving API with multiple columns, the column name is 'o' not 'v'.
(e.g : https://api.glassnode.com/v1/metrics/supply/hodl_waves)
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...