简体   繁体   English

熊猫的时间序列

[英]Time series in panda

How do I convert a date index into Time-based indexin g?如何将date index转换为基于时间的索引? so that i can later generate a month, weekday and a year这样我以后可以生成一个月,工作日和一年

I tried this code我试过这段代码

df['TRANS_DATE'] = pd.to_datetime(df['TRANS_DATE'], format='%m/%d/%Y %H:%M:%S')

but after I change it to Index the date revert back to show as object但是在我将其更改为索引后,日期恢复为显示为 object

What happens if you leave out the format option (letting it run to Default)?如果您忽略格式选项(让它运行到默认值)会发生什么? Also, it would be best if you show your original data.此外,最好显示您的原始数据。

Additional information - https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_datetime.html附加信息 - https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_datetime.html

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

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