I got a csv file that looks like this
valid,temp,pressure
2019-11-25 12:00,22,4
2019-11-22 12:00,24,4
2019-11-20 12:00,24,5
2019-11-17 12:00,26,5
I read the csv as a pandas dataframe and set the valid column as the index. I also convert it to a pd.datetime
df = pd.read_csv(file)
pd.to_datetime(df['valid']) # convert 'valid' column to pd.datetime objects
df = df.set_index('valid') # set the 'valid' column as index
Now I want to get the index as a datetime object of a certain row. How do I do that?
I tried this but it doesn't work
row = df.iloc[2]
print(row.index.month) # using .month just see if the returned object is a pd.datetime
AttributeError: 'Index' object has no attribute 'month'