如何解决将列更改为具有指定来源的日期时间格式
data['DATE'] = pd.to_datetime(data['DATE'],unit = 'ns',origin = "1899-12-30")
给予
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-23-d33b780eb61c> in <module>
----> 1 data['DATE'] = pd.to_datetime(data['DATE'],origin = "1899-12-30")
~/opt/anaconda3/lib/python3.7/site-packages/pandas/core/tools/datetimes.py in to_datetime(arg,errors,dayfirst,yearfirst,utc,format,exact,unit,infer_datetime_format,origin,cache)
700
701 if origin != "unix":
--> 702 arg = _adjust_to_origin(arg,unit)
703
704 tz = "utc" if utc else None
~/opt/anaconda3/lib/python3.7/site-packages/pandas/core/tools/datetimes.py in _adjust_to_origin(arg,unit)
499 ):
500 raise ValueError(
--> 501 f"'{arg}' is not compatible with origin='{origin}'; "
502 "it must be numeric with a unit specified"
503 )
ValueError: '0 1970-01-01 00:00:00.000043390
2 1970-01-01 00:00:00.000043605
3 1970-01-01 00:00:00.000043329
6 1970-01-01 00:00:00.000043601
8 1970-01-01 00:00:00.000043332
...
264815 1970-01-01 00:00:00.000043408
264816 1970-01-01 00:00:00.000043614
264826 1970-01-01 00:00:00.000043549
264830 1970-01-01 00:00:00.000043416
264834 1970-01-01 00:00:00.000043461
Name: DATE,Length: 74570,dtype: datetime64[ns]' is not compatible with origin='1899-12-30'; it must be numeric with a unit specified
任何帮助表示赞赏。
解决方法
如the docs中所述的
,如果您使用的格式类似于 julian (从...开始的天数),则还需要提供template<typename Key,typename Value>
void traverse(std::map<Key,Value>& m,void (*f)(Value)) {
for (auto&& [key,value] : m) {
f(value);
}
}
(“天” )。例如:
unit='D'
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。