回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我在使用pandas.to_datetime将jalali日期字符串转换为python日期时间对象时遇到一些问题
例如,当我运行以下简单代码时:</p>
<pre><code>print(pd.to_datetime('1399/05/02',format='%Y/%m/%d'))
</code></pre>
<p>我得到了这个错误:</p>
<pre><code>TypeError Traceback (most recent call last)
~\anaconda3\envs\tf2\lib\site-packages\pandas\core\arrays\datetimes.py in objects_to_datetime64ns(data, dayfirst, yearfirst, utc, errors, require_iso8601, allow_object)
1857 try:
-> 1858 values, tz_parsed = conversion.datetime_to_datetime64(data)
1859 # 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:
During handling of the above exception, another exception occurred:
OutOfBoundsDatetime Traceback (most recent call last)
in
1 #dbs.Irdate = pd.to_datetime(dbs.Irdate,format='%Y/%m/%d',yearfirst = True)
----> 2 print(pd.to_datetime('1399/05/02',format='%Y/%m/%d'))
~\anaconda3\envs\tf2\lib\site-packages\pandas\core\tools\datetimes.py in to_datetime(arg, errors, dayfirst, yearfirst, utc, format, exact, unit, infer_datetime_format, origin, cache)
754 result = convert_listlike(arg, format)
755 else:
--> 756 result = convert_listlike(np.array([arg]), format)[0]
757
758 return result
~\anaconda3\envs\tf2\lib\site-packages\pandas\core\tools\datetimes.py in _convert_listlike_datetimes(arg, format, name, tz, unit, errors, infer_datetime_format, dayfirst, yearfirst, exact)
445 errors=errors,
446 require_iso8601=require_iso8601,
--> 447 allow_object=True,
448 )
449
~\anaconda3\envs\tf2\lib\site-packages\pandas\core\arrays\datetimes.py in objects_to_datetime64ns(data, dayfirst, yearfirst, utc, errors, require_iso8601, allow_object)
1861 return values.view("i8"), tz_parsed
1862 except (ValueError, TypeError):
-> 1863 raise e
1864
1865 if tz_parsed is not None:
~\anaconda3\envs\tf2\lib\site-packages\pandas\core\arrays\datetimes.py in objects_to_datetime64ns(data, dayfirst, yearfirst, utc, errors, require_iso8601, allow_object)
1852 dayfirst=dayfirst,
1853 yearfirst=yearfirst,
-> 1854 require_iso8601=require_iso8601,
1855 )
1856 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()
pandas\_libs\tslib.pyx in pandas._libs.tslib.array_to_datetime()
pandas\_libs\tslibs\np_datetime.pyx in pandas._libs.tslibs.np_datetime.check_dts_bounds()
**OutOfBoundsDatetime: Out of bounds nanosecond timestamp: 1399-05-02 00:00:00**
</code></pre>
<blockquote>
<p>so
i use this Parameter <strong>errors='ignore'</strong> for fixing errors but result is unacceptable
for example :</p>
</blockquote>
<pre><code>print(pd.to_datetime('1399/05/02',format='%Y/%m/%d', errors='ignore'))
</code></pre>
<blockquote>
<p>result is : <strong>1399/05/02</strong> so you can see nothing change
i want some thing like this <strong>1399-05-02</strong> the python date time object
please help me</p>
</blockquote>