I’m trying to plot a dataframe using matplotlib.pyplot
, but I get the following error when plotting:
ValueError: view limit minimum -35738.3640567 is less than 1 and is an invalid Matplotlib date value. This often happens if you pass a non-datetime value to an axis that has datetime units.
According to the error, it seems like there's a non-datetime value in the 'datetime'
column, but there isn't.
I've tried using pd.to_datetime()
to change the format of the timestamp with pd.to_datetime(df_google['datetime'], format = '%d/%m/%Y')
, but nothing changes.
This is the code:
import matplotlib.pyplot as plt
df_google.plot()
plt.show()
df_google
is a dataframe with columns ['datetime', 'price']
and some of the values are the following:
datetime price
0 2018-05-15 1079.229980
1 2018-05-16 1081.770020
2 2018-05-17 1078.589966
3 2018-05-18 1066.359985
4 2018-05-21 1079.579956
5 2018-05-22 1069.729980
6 2018-05-23 1079.689941
7 2018-05-24 1079.239990
8 2018-05-25 1075.660034
9 2018-05-29 1060.319946
Can someone try to help me understand this type of error? Why does it say there's a non-datetime value when every value is a datetime Dtype
value? How can I plot this dataframe?