简体   繁体   English

按日期索引熊猫数据框

[英]Index pandas dataframe by date

I am trying to index my pandas dataframe by date by using:我正在尝试使用以下方法按日期索引我的 Pandas 数据框:

df = pd.to_datetime(df)

but am getting the following error:但我收到以下错误:

    ValueError: to assemble mappings requires at least that [year, month, day] 

    be specified: [day,month,year] is missing

My current pandas dataframe looks like this.我当前的熊猫数据框看起来像这样。

You're trying to convert the entire dataframe.您正在尝试转换整个数据帧。 Instead, you just want to apply the function to the dataframe index.相反,您只想将该函数应用于数据帧索引。

df.index = pd.to_datetime(df.index)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM