I got a csv file that looks like this
(我有一个看起来像这样的csv文件)
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.
(我将csv读取为pandas数据框,并将有效列设置为索引。)
I also convert it to a pd.datetime (我也将其转换为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'
ask by Vader translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…