import pandas as pd
# We assume here that you already have the http response
# response = requests.post( ... )
data = response.json()
gts_list = response.json()[0]
# Convert to DataFrame
rows = []
# Loop through the list of GTS
for gts in gts_list:
labels = gts.get("l", {})
attributes = gts.get("a", {})
# Loop through the values/timestamps for each GTS
for ts_us, *_, val in gts.get("v", []):
rows.append((
labels.get("siteName",""),
labels.get("deviceModel",""),
labels.get("deviceID",""),
labels.get("dataPoint",""),
attributes.get("description",""),
ts_us,
val,
attributes.get("engUnits",""),
attributes.get("subDeviceID",""),
attributes.get("assetType",""),
attributes.get("logicalNode",""),
attributes.get("dataObject",""),
attributes.get("subDataObject",""),
attributes.get("measurementType",""),
attributes.get("multiplier",""),
attributes.get("adder",""),
attributes.get("protocol","")
))
# Create a dataframe and set specify its columns
df = pd.DataFrame(rows, columns=[
"siteName","deviceModel","deviceID","dataPoint","description",
"timestamp","value","engUnits","subDeviceID","assetType",
"logicalNode","dataObject","subDataObject","measurementType",
"multiplier","adder","protocol","nx-agent-id"
])
# Convert unix microseconds time to date/time
df["timestamp"] = pd.to_datetime(df["timestamp"], unit="us", utc=True)
print(df.head())