|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
代码在一个只有10行数据的实现成功,在另外一个那里却不行
时间数据:
0 20150101
1 20150101
2 20150101
3 20150101
4 20150101
...
42811 20150430
42812 20150430
42813 20150430
42814 20150430
42815 20150430
Name: 销售日期, Length: 42816, dtype: int64
代码:
data['销售日期'] = pd.to_datetime(data['销售日期'],format='%Y%m%d')
错误:
Traceback (most recent call last):
File "D:\Anaconda3\lib\site-packages\pandas\core\tools\datetimes.py", line 448, in _convert_listlike_datetimes
values, tz = conversion.datetime_to_datetime64(arg)
File "pandas\_libs\tslibs\conversion.pyx", line 200, in pandas._libs.tslibs.conversion.datetime_to_datetime64
TypeError: Unrecognized value type: <class 'int'>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:/python/gyf/python01.py", line 16, in <module>
data['销售日期'] = pd.to_datetime(data['销售日期'],format='%Y%m%d')
File "D:\Anaconda3\lib\site-packages\pandas\util\_decorators.py", line 208, in wrapper
return func(*args, **kwargs)
File "D:\Anaconda3\lib\site-packages\pandas\core\tools\datetimes.py", line 774, in to_datetime
cache_array = _maybe_cache(arg, format, cache, convert_listlike)
File "D:\Anaconda3\lib\site-packages\pandas\core\tools\datetimes.py", line 156, in _maybe_cache
cache_dates = convert_listlike(unique_dates, True, format)
File "D:\Anaconda3\lib\site-packages\pandas\core\tools\datetimes.py", line 451, in _convert_listlike_datetimes
raise e
File "D:\Anaconda3\lib\site-packages\pandas\core\tools\datetimes.py", line 416, in _convert_listlike_datetimes
arg, format, exact=exact, errors=errors
File "pandas\_libs\tslibs\strptime.pyx", line 317, in pandas._libs.tslibs.strptime.array_strptime
File "pandas\_libs\tslibs\strptime.pyx", line 303, in pandas._libs.tslibs.strptime.array_strptime
ValueError: day is out of range for month |
|