# Error using pandas.to\_datetime()

**URL:** <https://forum.anaconda.com/t/error-using-pandas-to-datetime/88074>\
**Category:** Anaconda Code\
**Created:** [November 15, 2024, 2:54pm UTC](https://forum.anaconda.com/t/error-using-pandas-to-datetime/88074 "2024-11-15T14:54:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hennie](https://avatars.discourse-cdn.com/v4/letter/h/f5a800/32.png) [@hennie](https://forum.anaconda.com/u/hennie)\
**Post date:** [November 15, 2024, 2:54pm UTC](https://forum.anaconda.com/t/error-using-pandas-to-datetime/88074/1 "2024-11-15T14:54:20Z")

</div>

This code worked yesterday, so it appears something changed overnight. Does anybody have an idea what is going on here?  
I have a simple table

| Friday | Monday | Count |
| --- | --- | --- |
| 12/3/2021 | 12/6/2021 | 1 |
| 12/10/2021 | 12/13/2021 | 1 |
| 12/17/2021 | 12/20/2021 | 5 |
| 12/24/2021 | 12/27/2021 | 0 |
| and reading the data into a DataFrame to do a calculation I need to first convert the two date columns to datetime. This fails this morning. Below is the code: | | |
| df = to\_df(REF(“Table4[#All]”)) | | |
| df.Friday = pd.to\_datetime(df.Friday, format=“%Y-%m-%d”) | | |
| df.Monday = pd.to\_datetime(df.Monday, format=“%Y-%m-%d”) | | |
| mean2022 = df[df.Monday.dt.year == 2022].Count.mean() | | |

## The following error message is spilled in the log:

Traceback (most recent call last):  
File “‘Completed’!M6”, line 2, in   
df.Friday = pd.to\_datetime(df.Friday, format=“%Y-%m-%d”)  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File “/lib/python3.11/site-packages/pandas/core/tools/datetimes.py”, line 1068, in to\_datetime  
values = convert\_listlike(arg.\_values, format)  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File “/lib/python3.11/site-packages/pandas/core/tools/datetimes.py”, line 438, in \_convert\_listlike\_datetimes  
result, tz\_parsed = objects\_to\_datetime64ns(  
^^^^^^^^^^^^^^^^^^^^^^^^  
File “/lib/python3.11/site-packages/pandas/core/arrays/datetimes.py”, line 2177, in objects\_to\_datetime64ns  
result, tz\_parsed = tslib.array\_to\_datetime(  
^^^^^^^^^^^^^^^^^^^^^^^^  
File “pandas/\_libs/tslib.pyx”, line 427, in pandas.\_libs.tslib.array\_to\_datetime  
File “pandas/\_libs/tslib.pyx”, line 683, in pandas.\_libs.tslib.array\_to\_datetime  
File “pandas/\_libs/tslib.pyx”, line 833, in pandas.\_libs.tslib.\_array\_to\_datetime\_object  
File “pandas/\_libs/tslib.pyx”, line 655, in pandas.\_libs.tslib.array\_to\_datetime  
TypeError: \<class ‘pyodide.ffi.JsProxy’\> is not convertible to datetime

---

<div class="post-metadata">

**Author:** ![OwenPrice](https://dub1.discourse-cdn.com/anaconda/user_avatar/forum.anaconda.com/owenprice/32/5105_2.png) [@OwenPrice](https://forum.anaconda.com/u/OwenPrice)\
**Post date:** [November 15, 2024, 5:49pm UTC](https://forum.anaconda.com/t/error-using-pandas-to-datetime/88074/2 "2024-11-15T17:49:53Z")

</div>

Hi hennie and thanks for reporting this. That looks like a problem with the pyodide environment (that’s how we run Python in the add-in). I took your data and code just now and ran it in Anaconda Code without issue. However, we _did_ make a release yesterday so that may explain what’s happening. I know it’s not ideal, but could I ask that you uninstall and reinstall the add-in and re-test to see if the problem persists?

Let me know how you get on.

Owen

---

<div class="post-metadata">

**Author:** ![hennie](https://avatars.discourse-cdn.com/v4/letter/h/f5a800/32.png) [@hennie](https://forum.anaconda.com/u/hennie)\
**Post date:** [November 15, 2024, 7:02pm UTC](https://forum.anaconda.com/t/error-using-pandas-to-datetime/88074/3 "2024-11-15T19:02:34Z")

</div>

OK, I uninstalled the add-in, closed and re-opened Excel and re-loaded. Unfortunately I get the same error.

I then repeated with the additional step of rebooting my laptop, but still no luck. Is there a cache somewhere that should also be cleaned?

Hennie

---

<div class="post-metadata">

**Author:** ![hennie](https://avatars.discourse-cdn.com/v4/letter/h/f5a800/32.png) [@hennie](https://forum.anaconda.com/u/hennie)\
**Post date:** [November 15, 2024, 7:45pm UTC](https://forum.anaconda.com/t/error-using-pandas-to-datetime/88074/4 "2024-11-15T19:45:46Z")

</div>

I just copied the table as values to a fresh Excel document.  
When I do a simple:  
df = to\_df(REF(“Table4[#All]”))  
and set the Output to Excel Values, I do see the table in the output, however when I set Output to Python Object I get a #VALUE! error in the Excel sheet with no error shown in the log.

If I read with Output to Excel values and then look at the type of an element in one of the date columns,  
df = to\_df(REF(“Table4[#All]”))  
v = df.Friday[0]  
print(type(v))  
this is \<class ‘pyodide.ffi.JsProxy’\>. This does not seem right?

I see the data values in the above class is represented as:  
“Thu Dec 02 2021 18:00:00 GMT-0600 (Central Standard Time)”  
This appears the same/similar to what the .toString() method in javascript would produce from a JavaScript date value, if I’m Googling this correctly.

---

<div class="post-metadata">

**Author:** ![Jim\_Kitchen](https://avatars.discourse-cdn.com/v4/letter/j/f5a800/32.png) [@Jim\_Kitchen](https://forum.anaconda.com/u/Jim_Kitchen)\
**Post date:** [November 19, 2024, 10:23pm UTC](https://forum.anaconda.com/t/error-using-pandas-to-datetime/88074/5 "2024-11-19T22:23:16Z")

</div>

@hennie Thank you for finding this. It is definitely a bug in the new release and the updated datetime handling. We will work to get a fix out soon.

Just so you know, you shouldn’t need to call `to_datetime` anymore. Excel dates are automatically converted into Python `datetime` object, which pandas knows to convert to a timestamp column.

---

<div class="post-metadata">

**Author:** ![hennie](https://avatars.discourse-cdn.com/v4/letter/h/f5a800/32.png) [@hennie](https://forum.anaconda.com/u/hennie)\
**Post date:** [November 20, 2024, 5:24pm UTC](https://forum.anaconda.com/t/error-using-pandas-to-datetime/88074/6 "2024-11-20T17:24:01Z")

</div>

Thanks Jim. It now works fine.
