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 ...
随机推荐
- Linux下创建新用户
useradd -h查询使用方法 useradd -g sysadmin -d /home/devops -m -c "DevOps Installation User" -s / ...
- .net 中select和where的区别
Select(p=>p.ID==id) 这里选择的结果是通过p,访问迭代器,然后选取的是p.ID==id的结果,选择到的是bool对象 Where(p=>p.ID==id) 这里是过滤,p ...
- go read text file into string array
http://stackoverflow.com/questions/5884154/golang-read-text-file-into-string-array-and-write 方法一 pac ...
- 中文字号VS英文字号(磅)VS像素值
中文字号VS英文字号(磅)VS像素值八号=5磅(5pt) ==(5/72)*96=6.67 =6px 七号=5.5磅 ==(5.5/72)*96=7.3 =7px 小六=6.5磅 ==(6.5/72) ...
- 使用archlinux作为日常开发机已经半年了,随便写一下
机器配置 CPU: Intel Core i5-6200U CPU @ 2.8GHz RAM: 6114MiB / 7421MiB Resolution: 1920x2160 在arch下常用的软件 ...
- Appium常见问题(持续更新)
1.Original error: Could not parse activity from dumpsys 命令行:adb shell dumpsys cpuinfo 报:service du ...
- Javascript数组函数库
其实平时用的比较多的应该是push和pop,不过还是都记下来,以便后面使用. shift :删除原数组第一项,并返回删除元素的值:如果数组为空则返回undefined var a = [1,2,3,4 ...
- rabbitMQ学习(二)
一端发送,多端消费 发送端: import java.io.IOException; import com.rabbitmq.client.ConnectionFactory; import com. ...
- 转载-V.I.Arnold, beyond a mathematician
转自-http://blog.renren.com/blog/248100754/471276636 在AMS的首页上找到了三条讣告,依次是V.I.Arnold(1937-2010),W.Rudin( ...
- React Native 实现页面动态切换
第一步. 初始化子View constructor(props){ super(props); this.state = { isChange : true, itemView : (<Text ...