【发布时间】:2021-07-13 08:53:59
【问题描述】:
我有一个 DataFrame 作为图像中的那个,我想选择某个时间段内的行,例如从 2005 年初到 2007 年 7 月。
我已经尝试过this question as 中所说的
#Enero 2005-Julio 2007
AntCris=df.loc['2005-01-02 00:00:00':'2007-07-01 00:00:00']
或
AntCris=df.loc['2005-01-02':'2007-07-01 00:00:00']
甚至
AntCris=Datos.loc[Timestamp('2005-01-02 00:00:00'):Timestamp('2007-07-01 00:00:00')]
但我收到了错误TypeError: '<' not supported between instances of 'Timestamp' and 'str'。
此错误已在here 讨论,但我无法解决我的问题。我也试过用
重新索引我的dfA=pd.to_datetime(df.index)
df.set_index(A)
但我得到了TypeError: 'DatetimeIndex' object is not callable。
【问题讨论】:
标签: python pandas dataframe indexing