Skip to content Skip to sidebar Skip to footer

Attributeerror: 'numpy.datetime64' Object Has No Attribute 'toordinal'

I'm trying to draw a timeline import datetime as da import matplotlib.dates as dt # Data df = pd.DataFrame({'A': [da.datetime(2017,1,5,9,8), da.datetime(2017,1,5,9,9)

Solution 1:

If your aim is to plot horizontal lines using the A and B columns as x-axis and C column as y-axis, you can directly use arrays of dataframe. Added 1 day to B column since the time changes very minimal to observe that in graph:

df['B'] = df['B']+pd.Timedelta("1D")
ax = plt.subplot()
ax.hlines(df.C.values, df.A.values, df.B.values, lw=2)
plt.show()

Output Plot:

enter image description here

Solution 2:

I did not see any problem with the data type. The issue might be the date in column B. as an alternative to @Sandeep Kadapa, you can just set the max date, as xmax. For example:

 ax = plt.subplot()
ax.hlines(df.C.values, df.A.values, xmax='2017-01-02')
plt.show()

Post a Comment for "Attributeerror: 'numpy.datetime64' Object Has No Attribute 'toordinal'"