当前位置:网站首页>TypeError: Unrecognized value type: <class ‘str‘> ParserError: Unknown string format
TypeError: Unrecognized value type: <class ‘str‘> ParserError: Unknown string format
2022-07-25 18:25:00 【Data+Science+Insight】
TypeError: Unrecognized value type: <class 'str'> ParserError: Unknown string format
Catalog
TypeError: Unrecognized value type: ParserError: Unknown string format
problem :
import pandas as pd
# Define Panda Series
times = pd.Series(["2021-01-25", "2021/01/08", "2021", "Hello World", "Jan 4th, 2022"])
# Print Series
print("Series: \n", times, "\n")
# Convert Series to datetime
print("datetime: \n", pd.to_datetime(times))solve :
import pandas as pd
# Define Panda Series
times = pd.Series(["2021-01-25", "2021/01/08", "2021", "Hello World", "Jan 4th, 2022"])
# Print Series
print("Series: \n", times, "\n")
# Convert Series to datetime
print("datetime: \n", pd.to_datetime(times, errors = 'coerce'))Series: 0 2021-01-25 1 2021/01/08 2 2021 3 Hello World 4 Jan 4th, 2022 dtype: object datetime: 0 2021-01-25 1 2021-01-08 2 2021-01-01 3 NaT 4 2022-01-04 dtype: datetime64[ns]
Complete error :
Series: 0 2021-01-25 1 2021/01/08 2 2021 3 Hello World 4 Jan 4th, 2022 dtype: object
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
D:\anaconda\lib\site-packages\pandas\core\arrays\datetimes.py in objects_to_datetime64ns(data, dayfirst, yearfirst, utc, errors, require_iso8601, allow_object)
2084 try:
-> 2085 values, tz_parsed = conversion.datetime_to_datetime64(data)
2086 # If tzaware, these values represent unix timestamps, so we
pandas\_libs\tslibs\conversion.pyx in pandas._libs.tslibs.conversion.datetime_to_datetime64()
TypeError: Unrecognized value type: <class 'str'>
During handling of the above exception, another exception occurred:
ParserError Traceback (most recent call last)
<ipython-input-1-a11a96b9d90d> in <module>
8
9 # Convert Series to datetime
---> 10 print("datetime: \n", pd.to_datetime(times))
D:\anaconda\lib\site-packages\pandas\core\tools\datetimes.py in to_datetime(arg, errors, dayfirst, yearfirst, utc, format, exact, unit, infer_datetime_format, origin, cache)
803 result = arg.map(cache_array)
804 else:
--> 805 values = convert_listlike(arg._values, format)
806 result = arg._constructor(values, index=arg.index, name=arg.name)
807 elif isinstance(arg, (ABCDataFrame, abc.MutableMapping)):
D:\anaconda\lib\site-packages\pandas\core\tools\datetimes.py in _convert_listlike_datetimes(arg, format, name, tz, unit, errors, infer_datetime_format, dayfirst, yearfirst, exact)
470 errors=errors,
471 require_iso8601=require_iso8601,
--> 472 allow_object=True,
473 )
474
D:\anaconda\lib\site-packages\pandas\core\arrays\datetimes.py in objects_to_datetime64ns(data, dayfirst, yearfirst, utc, errors, require_iso8601, allow_object)
2088 return values.view("i8"), tz_parsed
2089 except (ValueError, TypeError):
-> 2090 raise e
2091
2092 if tz_parsed is not None:
D:\anaconda\lib\site-packages\pandas\core\arrays\datetimes.py in objects_to_datetime64ns(data, dayfirst, yearfirst, utc, errors, require_iso8601, allow_object)
2079 dayfirst=dayfirst,
2080 yearfirst=yearfirst,
-> 2081 require_iso8601=require_iso8601,
2082 )
2083 except ValueError as e:
pandas\_libs\tslib.pyx in pandas._libs.tslib.array_to_datetime()
pandas\_libs\tslib.pyx in pandas._libs.tslib.array_to_datetime()
pandas\_libs\tslib.pyx in pandas._libs.tslib.array_to_datetime_object()
pandas\_libs\tslib.pyx in pandas._libs.tslib.array_to_datetime_object()
pandas\_libs\tslibs\parsing.pyx in pandas._libs.tslibs.parsing.parse_datetime_string()
D:\anaconda\lib\site-packages\dateutil\parser\_parser.py in parse(timestr, parserinfo, **kwargs)
1372 return parser(parserinfo).parse(timestr, **kwargs)
1373 else:
-> 1374 return DEFAULTPARSER.parse(timestr, **kwargs)
1375
1376
D:\anaconda\lib\site-packages\dateutil\parser\_parser.py in parse(self, timestr, default, ignoretz, tzinfos, **kwargs)
647
648 if res is None:
--> 649 raise ParserError("Unknown string format: %s", timestr)
650
651 if len(res) == 0:
ParserError: Unknown string format: Hello World
边栏推荐
- Tkinter GUI address book management system
- Detailed introduction and application of GaN (comprehensive and complete)
- Three control methods of TestNG execution sequence
- "Digital security" alert NFT's seven Scams
- Software testing -- common testing tools
- win11下vscode 自动升级失败 There was an error while marking a file for deletion
- testng执行顺序的3中控制方法
- JZ71 跳台阶扩展问题
- C language -- 25 minesweeping game
- 解决You can change this value on the server by setting the ‘max_allowed_packet‘ variable报错
猜你喜欢

imx6 RTL8189FTV移植

解决You can change this value on the server by setting the ‘max_allowed_packet‘ variable报错

【网页性能优化】SPA(单页面应用)首屏加载速度慢怎么办?

c语言---25 扫雷游戏

Related operations of binary tree

Imx6 rtl8189ftv migration

使用sqldeveloper连接mysql

1---电子实物认知

This is a quick look-up table of machine & deep learning code

Related operations of figure
随机推荐
Diagonalization, power of a
This is a quick look-up table of machine & deep learning code
工程师必看的示波器探头安全使用说明书
MySQL lost the previous 0 after the decimal number type select
Practice of RTC performance automation tool in memory optimization scenario
这是一张机器&深度学习代码速查表
文件基础知识
Problems faced by cloud XR and main application scenarios of cloud XR
Analysis of regression problem, modeling and prediction
C language -- 25 minesweeping game
Jz71 jump step expansion problem
"Deprecated gradle features were used in this build, making it incompatible with gradle 6.0" problem solving
C盘空间不够 mklink解决VScode扩展迁移到其他盘
Circulaindicator component, which makes the indicator style more diversified
Tkinter GUI address book management system
[HAOI2015]树上操作
MATLAB中join函数使用
Chapter 5 Basic Scripting: Shell Variables
STM8S003F3 内部flash调试
408第二章线性表