WillKoehrsen / Data-Analysis

Data Science Using Python
https://medium.com/@williamkoehrsen/
MIT License
5.16k stars 3.64k forks source link

TypeError: <class 'datetime.date'> type object 2015-03-27 #16

Open yoonguk510 opened 6 years ago

yoonguk510 commented 6 years ago

I am getting this error

File "D:\anaconda\lib\site-packages\pandas\core\indexes\datetimes.py", line 133, in wrapper

TypeError: <class 'datetime.date'> type object 2015-03-27

julietxiao commented 5 years ago

I also met this error... Have you solve this problem?

yoonguk510 commented 5 years ago

Yes I have. There is a problem with the python file. You have to run it via jupiter notebook. It will work fine.

On Sun, Oct 7, 2018, 8:13 PM julietxiao notifications@github.com wrote:

I also met this error... Have you solve this problem?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/WillKoehrsen/Data-Analysis/issues/16#issuecomment-427644969, or mute the thread https://github.com/notifications/unsubscribe-auth/AaqjaWlmSU7GA-HqMXws2jJYKB-kBLHPks5uieHGgaJpZM4V6ZmT .

WillKoehrsen commented 5 years ago

I think this is an issue with the version of Pandas. Which version of Pandas were you using when you got the error?

VictorHM commented 5 years ago

I think this is an issue with the version of Pandas. Which version of Pandas were you using when you got the error?

I think you are spot on. I got this message regarding this:

FutureWarning: Comparing Series of datetimes with 'datetime.date'. Currently, the 'datetime.date' is coerced to a datetime. In the future pandas will not coerce, and a TypeError will be raised. To retain the current behavior, convert the 'datetime.date' to a datetime with 'pd.Timestamp'.

In the installation I have for Stocker, this is the version of Pandas and its dependencies Note that it is in a conda env that makes everything work (I had troubles making fbprophet work due to versions of pystan and others):

>>> pd.show_versions(as_json=False)

INSTALLED VERSIONS
------------------
commit: None
python: 3.6.6.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 61 Stepping 4, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.23.4
pytest: None
pip: 18.1
setuptools: 40.6.3
Cython: 0.29.3
numpy: 1.15.4
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.7.5
pytz: 2018.9
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 3.0.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

Hope this helps. Will try to go into it to see if I can modify Stocker.py to use new Pandas method. Regards.

sebdau commented 5 years ago

I'm having the same problem and went through similar install issues as described by @VictorHM.

I'm new to Python so I'd apppriciate if one could point out a solution or workaround.

Thanks a lot!

sebdau commented 5 years ago

22 Solved the type problem for me!

htuhxf commented 5 years ago

I got the same problem with pandas0.23.4, just as described by VictorHM. Solved the problem by "pd.to_datetime(df['date'], format='%Y%m%d').apply(lambda x: x.date())".the stackoverflow link is here

yoonguk510 commented 5 years ago

Late, but thank you for your help :)

On Mon, Apr 8, 2019 at 12:20 PM Sean notifications@github.com wrote:

I got the same problem with pandas0.23.4, just as described by VictorHM. Solved the problem by "pd.to_datetime(df['date'], format='%Y%m%d').apply(lambda x: x.date())".the stackoverflow link is here https://stackoverflow.com/questions/41783003/how-do-i-convert-timestamp-to-datetime-date-in-pandas-dataframe

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/WillKoehrsen/Data-Analysis/issues/16#issuecomment-480669638, or mute the thread https://github.com/notifications/unsubscribe-auth/AaqjaR6KhHuDVAK-tZu54KihMVtFJhx_ks5verVmgaJpZM4V6ZmT .

angelotc commented 4 years ago

I think you are spot on. I got this message regarding this:

FutureWarning: Comparing Series of datetimes with 'datetime.date'. Currently, the 'datetime.date' is coerced to a datetime. In the future pandas will not coerce, and a TypeError will be raised. To retain the current behavior, convert the 'datetime.date' to a datetime with 'pd.Timestamp'.

wrapping the datetime in pd.Timestamp(<your_date>) worked for me to get around that warning.