DashBookProject / Plotly-Dash

110 stars 65 forks source link

Error in twitter_app.py #9

Open gmrwvu opened 1 year ago

gmrwvu commented 1 year ago

I received this error when attempting to run the twitter_app.py script:

C:\Users\gmrwv\PycharmProjects\my-first-app\venv\Scripts\python.exe C:\gmrPy\twitter_app.py Traceback (most recent call last): File "C:\gmrPy\twitter_app.py", line 10, in df["date_time"] = pd.to_datetime(df["date_time"]) File "C:\Users\gmrwv\PycharmProjects\my-first-app\venv\lib\site-packages\pandas\core\tools\datetimes.py", line 1050, in to_datetime values = convert_listlike(arg._values, format) File "C:\Users\gmrwv\PycharmProjects\my-first-app\venv\lib\site-packages\pandas\core\tools\datetimes.py", line 453, in _convert_listlike_datetimes return _array_strptime_with_fallback(arg, name, utc, format, exact, errors) File "C:\Users\gmrwv\PycharmProjects\my-first-app\venv\lib\site-packages\pandas\core\tools\datetimes.py", line 484, in _array_strptime_with_fallback result, timezones = array_strptime(arg, fmt, exact=exact, errors=errors, utc=utc) File "pandas_libs\tslibs\strptime.pyx", line 530, in pandas._libs.tslibs.strptime.array_strptime File "pandas_libs\tslibs\strptime.pyx", line 351, in pandas._libs.tslibs.strptime.array_strptime ValueError: time data "27/12/2016 04:04" doesn't match format "%m/%d/%Y %H:%M", at position 9. You might want to try:

Process finished with exit code 1

gmrwvu commented 1 year ago

I resolved the error by changing the original twitter_app.py: from: df["date_time"] = pd.to_datetime(df["date_time"]) to df["date_time"] = pd.to_datetime(df["date_time"], format="%d/%m/%Y %H:%M")

Kay19Dev commented 2 months ago

This error is caused due to the tweets.csv having the date format as DD/MM/YYYY, but the default format pd.to_datetime(df["date_time"]) expects is MM/DD/YYYY.

I resolved this slightly different than how gmrwvu did by changing line 10 to: pd.to_datetime(df["date_time"], dayfirst=True)