I'm able to fetch the data, but I'm getting issues with the transformation process. Here's my code:
import requests
import pandas as pd
api_url = "https://api.open-meteo.com/v1/forecast?latitude=51.4325&longitude=6.7652&hourly=shortwave_radiation,direct_radiation,diffuse_radiation,direct_normal_irradiance,terrestrial_radiation"
response = requests.get(api_url)
if response.status_code == 200:
api_data = response.json() # Die API-Daten im JSON-Format
else:
print("Fehler beim Abrufen der API-Daten")
api_data = None
df = pd.DataFrame(api_data)
df['hourly']=df['hourly'].replace("[","", regex=False)
df_new = df['hourly'].str.split(',',expand = True)
#df[['0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23']] = df['hourly'].str.split(',',expand=True)
df['hourly']
df.shape
dfP = df['hourly']
print(df)
I'm trying to transform the 'hourly' data into the structure where it splits into columns labeled from 0 to 24. If anyone could guide me on how to achieve this, I'd greatly appreciate it. Thank you!