0

I am trying to rearrange a DataFrame. Currently, I have 1035 rows and 24 columns, one for each hour of the day. I want to make this a array with 1035*24 rows. If you want to see the data it can be extracted from the following JSON file:

url = "https://www.svk.se/services/controlroom/v2/situation?date={}&biddingArea=SE1"

svk = []
for i in parsing_range_svk:
    data_json_svk = json.loads(urlopen(url.format(i)).read())
    svk.append([v["y"] for v in data_json_svk["Data"][0]["data"]])

This is the code I am using to rearrange this data, but it is not doing the job. The first obeservation is in the right place, then it starts getting messy. I have not been able to figure out where each observation goes.

svk = pd.DataFrame(svk)
date_start1 = datetime(2020, 1, 1)
date_range1 = [date_start1 + timedelta(days=x) for x in range(1035)]
date_svk = pd.DataFrame(date_range1, columns=['date'])
svk['date'] = date_svk['date']
svk.drop(24, axis=1, inplace=True)

consumption_svk_1 = (svk.melt('date', value_name='SE1_C')
         .assign(date = lambda x: x['date'] + 
                                pd.to_timedelta(x.pop('variable').astype(float), unit='h'))
         .sort_values('date', ignore_index=True))

0 Answers0