在 Pandas 数字 sas 日期转换为日期时间
it1352
帮助2人
问题说明
我正在使用 Pandas 0.18 和 read_sas
加载 sas7bdat
数据集.
I am using Pandas 0.18 and read_sas
to load a sas7bdat
dataset.
Pandas 数据框中的日期显示为:
The dates in the Pandas dataframe appear as:
Out[56]:
0 19411.0
1 19325.0
2 19325.0
3 19443.0
4 19778.0
Name: sas_date, dtype: float64
pd.to_datetime
无法识别此格式.我应该怎么做才能正确解析日期?
pd.to_datetime
does not recognize this format. What should I do parse the date correctly?
谢谢!
正确答案
#1
根据这个链接,
[A] SAS 日期值是一个值,表示之间的天数1960 年 1 月 1 日和指定日期
[A] SAS date value is a value that represents the number of days between January 1, 1960, and a specified date
因此,如果我们将数字转换为 Pandas Timedeltas 并将它们添加到1960-1-1
我们可以恢复日期:
Therefore, if we convert the numbers to Pandas Timedeltas and add them to 1960-1-1
we can recover the date:
import numpy as np
import pandas as pd
ser = pd.Series([19411.0, 19325.0, 19325.0, 19443.0, 19778.0])
ser = pd.to_timedelta(ser, unit='D') pd.Timestamp('1960-1-1')
产量
0 2013-02-22
1 2012-11-28
2 2012-11-28
3 2013-03-26
4 2014-02-24
dtype: datetime64[ns]
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tangicaie
系列文章
更多
同类精品
更多
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20