Conversion Error on DQ server but works locally

Hello. I have code that work on my browser using Anaconda and it’s raising an Error in the DQ Jupyter notebook.

Here’s the code

# create a us dollar to euro dataframe and add 30 day rolling mean column
us_dollar = x_rates[["date","us_dollar"]].copy()
us_dollar["rolling_mean_30"] = us_dollar["us_dollar"].rolling(30).mean()

# line graph for dollar to euro exchange rate
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
%matplotlib inline
fig, ax = plt.subplots(figsize=(10,3.75))
ax.plot(us_dollar["date"], us_dollar["rolling_mean_30"])
ax.set(xlabel="Year",
       ylabel="US dollar",
       title="US Dollar to Euro Exhcange Rates")
ax.set_xticks(["2000-01-04 00:00:00", "2005-01-04 00:00:00", "2010-01-04 00:00:00",
               "2015-01-04 00:00:00", "2020-01-04 00:00:00"])
ax.set_xticklabels([2000,2005,2010,2015,2020])
plt.show()

Locally yields

But on the DQ server I get

ConversionError: Failed to convert value(s) to axis units: ['2000-01-04 00:00:00', '2005-01-04 00:00:00', '2010-01-04 00:00:00', '2015-01-04 00:00:00', '2020-01-04 00:00:00']

linked to this

AttributeError: 'numpy.str_' object has no attribute 'toordinal'

I have tried it multiple times in both environments. Works fine in one and not the other.

Thanks for any help.

1 Like

Hi Bruce,

You can find useful this post.

1 Like

Thanks for your help. I’m not sure if I see the direct connection.

Again, the code works fine and produces the plot with the x ticks in the correct place using Colab or a Jupyter notebook through Anaconda.

But I get the error whenever I run the code on the Dataquest notebook.

In this post Sahil mentions that dataquest is running Pandas version 0.22.0. The post is from a couple years ago but I wonder if it’s the same type of thing?

1 Like

Hi Bruce,

The issue is most probably exactly because of the pandas version difference between the DQ platform and Anaconda. The one of DQ is an older one. As far as I know, it’s in the process of updating, but it will take time anyway. To check the pandas version either in Anaconda or on the DQ platform, run the following code:

import pandas as pd
pd.__version__

Moreover, it can happen that different DQ lessons have different pandas versions (at least it happenned so with Python versions). So you have to run the code above exactly in the screen with the issue.

If you run your code in an older pandas version (the one of DQ), you’ll get the ConversionError which you can try to fix using the STO post I recommended you earlier. However, it makes more sense to run your code locally in Anaconda, on a newer pandas version, instead of learning tricks for an older version.

1 Like