pandas中将timestamp转为datetime
参考自:http://stackoverflow.com/questions/35312981/using-pandas-to-datetime-with-timestamps
在pandas DataFrame中将timestamp转为datetime,关键要使用unit='s'。而不是ms、us或者其他选项。
0 1450753200.123213,
1 1450756800.123213,
2 1450760400.123213,
3 1450764000.123213,
4 1450767600.123213,
转换为datetime
In [106]:
pd.to_datetime(df['timestamp'], unit='s')
Out[106]:
index
0 2015-12-22 03:00:00
1 2015-12-22 04:00:00
2 2015-12-22 05:00:00
3 2015-12-22 06:00:00
4 2015-12-22 07:00:00
Name: timestamp, dtype: datetime64[ns]
转为字符串
In [107]:
pd.to_datetime(df['timestamp'], unit='s').dt.strftime('%Y-%m-%d %H:%M')
Out[107]:
index
0 2015-12-22 03:00
1 2015-12-22 04:00
2 2015-12-22 05:00
3 2015-12-22 06:00
4 2015-12-22 07:00
Name: timestamp, dtype: object
pandas中将timestamp转为datetime的更多相关文章
- python pandas Timestamp 转为 datetime 类型
In [11]: ts = pd.Timestamp('2014-01-23 00:00:00', tz=None) In [12]: ts.to_pydatetime() Out[12]: date ...
- 设置TIMESTAMP和DATETIME的自动初始化及自动更新
最近有一个关于MySQL版本升级的事,涉及到一些关于时间类型的细节问题需要查明,因此到官网找到相关文章,翻出来比较方便自己理解,博客这里也贴一下. 参考官网网址: https://dev.mysql. ...
- MySQL案例之Timestamp和Datetime
mysql数据库常用的时间类型有timestamp和datetime,两者主要区别是占用存储空间长度不一致.可存储的时间也有限制,但针对不同版本下,timestamp字段类型的设置需要慎重,因为不注意 ...
- pandas中Timestamp类用法讲解
由于网上关于Timestamp类的资料比较少,而且官网上面介绍的很模糊,本文只是对如何创建Timestamp类对象进行简要介绍,详情请读者自行查阅文档. 以下有两种方式可以创建一个Timestamp对 ...
- MySQL中有关TIMESTAMP和DATETIME的总结
一.MySQL中如何表示当前时间? 其实,表达方式还是蛮多的,汇总如下: CURRENT_TIMESTAMP CURRENT_TIMESTAMP() NOW() LOCALTIME LOCALTIME ...
- Opencv中将CvMat转为IplImage
Opencv中将CvMat转为IplImage,并在内存获得起头指针,而不用cvSaveImage(),贴上代码 IplImage * imgg = NULL; imgg = cvCreateImag ...
- Mysql存储日期类型用int、timestamp还是datetime?
通常存储时间用datetime类型,现在很多系统也用int存储时间,它们有什么区别?个人更喜欢使用int这样对于日期计算时比较好哦,下面我们一起来看到底那种会好些. int ().4个字节存储,INT ...
- C#中 String 格式的日期时间 转为 DateTime
C#中并没有表示时间的变量,只有DateTime,所以要表示时间,可以用TimeSpan表示. 方法一:Convert.ToDateTime(string) string格式有要求,必须是yyyy-M ...
- TIMESTAMP和DATETIME的区别
TIMESTAMP和DATETIME的区别 1. 存储空间不同 a) TIMESTAMP占用4个字节 b) DATETIME占用8个字节 2. 受时区影响 c) TIMESTAMP实际记录的是1970 ...
随机推荐
- su with hyphen and without - su带横杠和不带横杠
The difference between "-" and "no hyphen" is that the latter keeps your existin ...
- sqlserver2000 在查询时产生序号列的办法
用的是数据库sqlserver2000,唉,有点老了,好处是到处都有,安装方便. select ( select count(*) from temp_gzsphzb as t1 where spid ...
- 安装libudev-dev,解决依赖错误
http://stackoverflow.com/questions/17181073/ubuntu-12-04-libudev-dev-wont-install-because-of-depende ...
- FLAG_ACTIVITY_CLEAR_TOP
看了一篇相关的文章,感觉还不错,链接http://www.cnblogs.com/lwbqqyumidi/p/3775479.html
- 怎么创建一个Database快照
How to create the database Snapshot: use mastergoif not exists (select * from sys.databases where na ...
- spring web mvc中遇到的错误以及学习小记(持续记录)
错误:cvc-complex-type.2.4.a: 发现了以元素 'init-param' 开头的无效内容.应以 '{"http://java.sun.com/xml/ns/javaee& ...
- 施耐德Sepam 40系列备自投逻辑
1# 主供: VL1= NOT PVTS_1_3 V1 = VL1 AND P59_1_7 AND P59_1_8 AND P59_1_9VL2 = VL1 AND I12 AND I21 AND I ...
- wordpress woodstock主题导入demo xml文件 execution time out
1.已设置php.ini max_execution_time = 240 导入显示设置60 2.wp-config.php 添加 set_time_limit(600); 无效 3. .htacce ...
- BIO,NIO,AIO
同步阻塞IO(JAVA BIO): 同步并阻塞,服务器实现模式为一个连接一个线程,即客户端有连接请求时服务器端就需要启动一个线程进行处理,如果这个连接不做任何事情会造成不必要的线程开销,当然可 ...
- leetcode 171
171. Excel Sheet Column Number Related to question Excel Sheet Column Title Given a column title as ...