当前位置:网站首页>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
边栏推荐
- Tensor to img && imge to tensor (pytorch的tensor转换)
- Keil5 "loading PDSC debug description failed for STMicroelectronics stm32hxxxxxxx" solution
- 遍历数组的方法有哪些?for循环 forEach for/in for/of map的性能又有什么差别 该如何选择?
- 基于Caffe ResNet-50网络实现图片分类(仅推理)的实验复现
- BiSeNet v1
- srec_cat 常用参数的使用
- [QNX Hypervisor 2.2用户手册]9.5 dump
- If you want to do a good job in software testing, you can first understand ast, SCA and penetration testing
- Tkinter GUI address book management system
- win11下vscode 自动升级失败 There was an error while marking a file for deletion
猜你喜欢

Boomi won the "best CEO in diversity" and the "best company in career growth" and ranked among the top 50 in the large company category

CircleIndicator组件,使指示器风格更加多样化

"Digital security" alert NFT's seven Scams

Stm8s003f3 internal flash debugging

Introduction to cloud XR and development opportunities of cloud XR in 5g Era

ORB_ Slam3 recurrence - Part I

"Jargon" | what kind of experience is it to efficiently deliver games with Devops?

Oracle uses impdp import to report an error: ora-39001: invalid parameter value ora-39000: dump file description error ora-39088: file name cannot contain path description

1---电子实物认知

Talking about Devops monitoring, how does the team choose monitoring tools?
随机推荐
Tensor to img && imge to tensor (pytorch的tensor转换)
tkinter GUI版通信录管理系统
Design practice of Netease strictly selecting inventory center
CircleIndicator组件,使指示器风格更加多样化
Use of LCD screen of kendryte k210 on FreeRTOS
Problems faced by cloud XR and main application scenarios of cloud XR
Flexible current probe selection guide
NC68 跳台阶
Linux启动mysql报错
408第二章线性表
1---电子实物认知
How to add EXE file to boot
Application of current probe in ECU and electrical system current measurement
MATLAB中join函数使用
Detailed explanation of super full mavan label
Three control methods of TestNG execution sequence
Keil5 "loading PDSC debug description failed for STMicroelectronics stm32hxxxxxxx" solution
[QNX Hypervisor 2.2用户手册]9.5 dump
This is a quick look-up table of machine & deep learning code
【网页性能优化】SPA(单页面应用)首屏加载速度慢怎么办?