TypeError:ufunc减法不能使用类型为dtype('< M8 [ns]')和dtype('float64')的操作数 [英] TypeError: ufunc subtract cannot use operands with types dtype('<M8[ns]') and dtype('float64')
问题描述
通过遵循senddex的视频教程,我遇到了错误代码.但是,当我想在ax2上为我的Volume绘制条形图时,它会给我错误代码,如本主题中所列.请帮忙.我是Python 0编程新手.
I had met an error code by following the video tutorial of sentdex. When i want to plot a bar graph on ax2 for my Volume, however, it give me error code as listed at the topic. Please help. I am new in Python 0 experience in programming.
import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import style
import pandas as pd
import pandas_datareader.data as web
style.use('ggplot')
df = pd.read_csv('C:\\Users\\ngjun95\\Downloads\\7120.KL.csv', parse_dates=True, index_col=0)
df['100ma'] = df['Adj Close'].rolling(window=100, min_periods=0).mean()
print(df.head())
ax1 = plt.subplot2grid((6,1), (0,0), rowspan=5, colspan=1)
ax2 = plt.subplot2grid((6,1), (5,0), rowspan=1, colspan=1, sharex=ax1)
ax1.plot(df.index, df['Adj Close'])
ax1.plot(df.index, df['100ma'])
ax2.bar(df.index, df['Volume'])
plt.show()
推荐答案
似乎是Matplotlib和Numpy之间的日期转换问题. https://github.com/matplotlib/matplotlib/issues/9610
Seems like a date conversion issue between Matplotlib and Numpy. https://github.com/matplotlib/matplotlib/issues/9610
我有同样的问题,时间最长.
I had the same issue for the longest time.
df.index.to_pydatetime()对我有用.
df.index.to_pydatetime() works for me.
这篇关于TypeError:ufunc减法不能使用类型为dtype('< M8 [ns]')和dtype('float64')的操作数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!