当前位置:   article > 正文

pandas中Timestamp类用法讲解

panda timestamp to count second

pandas中Timestamp类用法讲解

由于网上关于Timestamp类的资料比较少,而且官网上面介绍的很模糊,本文只是对如何创建Timestamp类对象进行简要介绍,详情请读者自行查阅文档

以下有两种方式可以创建一个Timestamp对象:

1. Timestamp()的构造方法

  1. import pandas as pd
  2. from datetime import datetime as dt
  3. p1=pd.Timestamp(2017,6,19)
  4. p2=pd.Timestamp(dt(2017,6,19,hour=9,minute=13,second=45))
  5. p3=pd.Timestamp("2017-6-19 9:13:45")
  6. print("type of p1:",type(p1))
  7. print(p1)
  8. print("type of p2:",type(p2))
  9. print(p2)
  10. print("type of p3:",type(p3))
  11. print(p3)
  12. 输出:
  13. ('type of p1:', <class 'pandas.tslib.Timestamp'>)
  14. 2017-06-19 00:00:00
  15. ('type of p2:', <class 'pandas.tslib.Timestamp'>)
  16. 2017-06-19 09:13:45
  17. ('type of p3:', <class 'pandas.tslib.Timestamp'>)
  18. 2017-06-19 09:13:45

2. to_datetime()方法

  1. import pandas as pd
  2. from datetime import datetime as dt
  3. p4=pd.to_datetime("2017-6-19 9:13:45")
  4. p5=pd.to_datetime(dt(2017,6,19,hour=9,minute=13,second=45))
  5. print("type of p4:",type(p4))
  6. print(p4)
  7. print("type of p5:",type(p5))
  8. print(p5)
  9. 输出:
  10. ('type of p4:', <class 'pandas.tslib.Timestamp'>)
  11. 2017-06-19 09:13:45
  12. ('type of p5:', <class 'pandas.tslib.Timestamp'>)
  13. 2017-06-19 09:13:45
posted @ 2017-06-19 09:32 neu_张康 阅读( ...) 评论( ...) 编辑 收藏
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/66490
推荐阅读
相关标签
  

闽ICP备14008679号