在 Pandas 转换 SAS 日期时间
it1352
帮助3人
问题说明
我正在使用 Pandas 通过 read_sas
SAS 数据集中有一个 datetime 变量,在 Pandas 中显示为:
There is a datetime variable in the SAS dataset, which appears in Pandas as:
1.775376e 09
将其转换为 str
后,日期为:
Once I convert it to str
the date is:
1775376002.0
SAS 中的相应日期(不在我的 Pandas 数据集中)似乎是 DATETIME21.2
The corresponding date in SAS (not in my Pandas dataset) appears to be a DATETIME21.2
04APR2016:08:00:02.00
我尝试使用转换它
pd.to_datetime(df.mysasdate,format='%d%m%Y%H%M%S')
没有成功
TypeError: 'float' object is unsliceable
有什么想法吗?谢谢!
正确答案
#1
SAS 日期值
是一个值,表示从 1960 年 1 月 1 日到指定日期之间的天数.链接
is a value that represents the number of days between January 1, 1960, and a specified date. link
所以你可以转换数字 to_timedelta
并添加
date
1960-01-01 00:00:00
So you can convert number to_timedelta
and add date
1960-01-01 00:00:00
df = pd.DataFrame({'mysasdate':[1775376002.0, 1775377002.0]})
print (df)
mysasdate
0 1.775376e 09
1 1.775377e 09
print (pd.to_timedelta(df['mysasdate'], unit='s') pd.datetime(1960, 1, 1))
0 2016-04-04 08:00:02
1 2016-04-04 08:16:42
Name: mysasdate, dtype: datetime64[ns]
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tangicahj
系列文章
更多
同类精品
更多
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
检查邮件是否发送成功
it1352 07-25 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20