下面是代码
import pandas as pd
pd.to_datetime(pd.DataFrame(['12/4/1982']))
字符串
然而,有了这个,我得到以下错误
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.11/site-packages/pandas/core/tools/datetimes.py", line 1053, in to_datetime
result = _assemble_from_unit_mappings(arg, errors, utc)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/pandas/core/tools/datetimes.py", line 1161, in _assemble_from_unit_mappings
unit = {k: f(k) for k in arg.keys()}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/pandas/core/tools/datetimes.py", line 1161, in <dictcomp>
unit = {k: f(k) for k in arg.keys()}
^^^^
File "/usr/local/lib/python3.11/site-packages/pandas/core/tools/datetimes.py", line 1156, in f
if value.lower() in _unit_map:
^^^^^^^^^^^
AttributeError: 'int' object has no attribute 'lower'
型
你能帮我弄明白我的代码有什么问题吗?
1条答案
按热度按时间yeotifhr1#
您将整个框架提供给
pd.to_datetime
。在本例中(来自文档):.如果提供了DataFrame,则该方法至少需要以下列:“year”、“month”、“day”。列“year”必须以4位格式指定。
请尝试以下操作:
字符串
印刷品:
型