当前位置:   article > 正文

python中使用pandas提取日期信息

python中使用pandas提取日期信息

提取日期操作参照→链接:https://blog.csdn.net/meiqi0538/article/details/82558000

  1. import numpy as np
  2. import pandas as pd
  3. from pandas import Series, DataFrame
  4. from datetime import datetime
  5. data = {'stamp': ['2016-12-01 00:00:00', '2016-12-01 01:05:10' ,'2016-12-01 02:10:20', '2016-12-01 03:15:30',
  6. '2016-12-01 04:20:40','2016-12-01 05:25:50','2016-12-01 06:30:00','2016-12-01 07:35:10',
  7. '2016-12-01 08:40:20','2016-12-01 09:45:30','2016-12-01 10:50:40','2016-12-01 11:55:50'],
  8. }
  9. df = pd.DataFrame(data)
  10. df

结果如下:

提取数据中日期:

  1. from pandas import to_datetime
  2. df_dt=to_datetime(df.stamp)
  3. s_y=df_dt.dt.year
  4. s_M
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/230278?site
推荐阅读
相关标签
  

闽ICP备14008679号