Closed GaussEuler closed 6 years ago
Hey. Sorry you're having issues and thanks for reaching out. What's citibike.type
?
Also, can you please provide the full traceback?
I can reproduce, seems like an incompatible change in pandas 0.21.0
This workaround seems to work:
plt.xticks(xticks.astype("int"), xticks.strftime("%a %m-%d"), rotation=90, ha="left")
note the .astype("int")
Thank you so much Dr. Muller. Yes, the workaround code works perfectly! Again, thanks a lot for such a quick response. I sincerely appreciate. (I was trying with astype('float') but it was not working)
citibike.type Traceback (most recent call last):
File "
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\generic.py", line 3614, in getattr return object.getattribute(self, name)
AttributeError: 'Series' object has no attribute 'type'
And herein is the full Traceback of the initial problem Traceback (most recent call last):
File "
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 710, in runfile execfile(filename, namespace)
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 101, in execfile exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/Numerical Nikhilesh/.spyder-py3/temp.py", line 26, in
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\pyplot.py", line 1618, in xticks locs = ax.set_xticks(args[0])
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axes_base.py", line 3003, in set_xticks ret = self.xaxis.set_ticks(ticks, minor=minor)
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axis.py", line 1647, in set_ticks self.set_view_interval(min(ticks), max(ticks))
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axis.py", line 1996, in set_view_interval self.axes.viewLim.intervalx = (min(vmin, vmax, Vmin),
File "pandas/_libs/tslib.pyx", line 1166, in pandas._libs.tslib._Timestamp.richcmp
TypeError: Cannot compare type 'Timestamp' with type 'float'
Sorry, I had meant .dtype
but yeah, this is http://pandas-docs.github.io/pandas-docs-travis/whatsnew.html#no-automatic-matplotlib-converters
Thank you for providing that link. Yes, with the help of converter, one then can use your code from the book exactly as it is without adding .astype("int") Thank you again sir.
Will be fixed in the next print, I fixed it in this repo, too.
Respected Dr. Muller, please help me with this error. Running your code as stated exactly in the book in Chapter 4, In[50] (p-245) gives me the following error: TypeError: Cannot compare type 'Timestamp' with type 'float'
The code is as follows: import matplotlib.pyplot as plt import pandas as pd import mglearn
citibike = mglearn.datasets.load_citibike()
plt.figure(figsize=(10, 3)) xticks = pd.date_range(start=citibike.index.min(), end=citibike.index.max(), freq='D') plt.xticks(xticks, xticks.strftime("%a %m-%d"), rotation=90, ha="left") plt.plot(citibike, linewidth=1) plt.xlabel("Date") plt.ylabel("Rentals")
I am running this code in (Anaconda) Spyder, version 3.2.4 and Pandas version is 0.21.0
Thank you, Sincerely, Nikhilesh