I dont know how to transform data in my column 'datetime' with this format:
2020-01-01T00:00:00.000+01:00
in to:
Jan-2020
I've tried with this:
works_data["datetime"] = pd.to_datetime(works_data["datetime"], utc=True).dt.strftime('%b-%Y')
but doens't work... it returns the date in that format but with one less month.
For example, for 2020-01-01T00:00:00.000+01:00
returns Dec-2019
... I dont know why....
Could anybody help me with this problem?
EDIT:
The actual code that is working.
import requests
import pandas as pd
import json
from pandas.io.json import json_normalize
import datetime
import time
url = "https://apidatos.ree.es/es/datos/generacion/estructura-generacion?start_date=2020-01-01T00:00&end_date=2020-12-31T22:00&time_trunc=month"
response = requests.get(url)
data = response.json()
df = pd.DataFrame(data['included'])
works_data = pd.json_normalize(data=df['attributes'], record_path='values',
meta=['title'])
And if i print the works_data, it returns:
value percentage datetime title
0 3.726053e+06 0.163889 2020-01-01T00:00:00.000+01:00 Hidráulica
1 2.837911e+06 0.139561 2020-02-01T00:00:00.000+01:00 Hidráulica
2 3.112718e+06 0.148076 2020-03-01T00:00:00.000+01:00 Hidráulica
3 2.861429e+06 0.163464 2020-04-01T00:00:00.000+02:00 Hidráulica
4 2.858050e+06 0.159065 2020-05-01T00:00:00.000+02:00 Hidráulica
... ... ... ... ...
107 3.504687e+04 0.002002 2020-04-01T00:00:00.000+02:00 Residuos renovables
108 3.665093e+04 0.002040 2020-05-01T00:00:00.000+02:00 Residuos renovables
109 4.231355e+04 0.002197 2020-06-01T00:00:00.000+02:00 Residuos renovables
110 4.313452e+04 0.001803 2020-07-01T00:00:00.000+02:00 Residuos renovables
111 3.159610e+04 0.003548 2020-08-01T00:00:00.000+02:00 Residuos renovables
Any idea how to continue to transform the datetime column?