matplotlib:为什么在python中,绘制历史会导致索引错误?

matplotlib:为什么在python中,绘制历史会导致索引错误?,python,matplotlib,Python,Matplotlib,我正在学习数据集 由于@Vaishali@Ultra-TLC@Tom's,数据被导入 p_data = 'https://raw.githubusercontent.com/MachineIntellect/dataset.ml/master/horse_colic.csv' df = pd.read_csv(p_data) df = df.replace("?", np.NaN) df = df.astype(np.float) 为了获得要打印的列数和行数,这段代码也很有效 %matplot

我正在学习数据集

由于@Vaishali@Ultra-TLC@Tom's,数据被导入

p_data = 'https://raw.githubusercontent.com/MachineIntellect/dataset.ml/master/horse_colic.csv'
df = pd.read_csv(p_data)
df = df.replace("?", np.NaN)
df = df.astype(np.float)
为了获得要打印的列数和行数,这段代码也很有效

%matplotlib inline
n_col = 4
n_row = int(math.ceil(df.shape[1] * 1.0/n_col))
当我试图描绘历史时

fig, axes = plt.subplots(n_row, n_col, figsize=(15, 30))
plt.tight_layout()
for i, col in enumerate(df.columns):
    pos_i = i / n_col
    pos_j = i % n_col
    df.groupby("cp_data")[col].plot.hist(title=col, alpha=0.5, ax=axes[pos_i, pos_j]);
出现错误

IndexError                                Traceback (most recent call last)
<ipython-input-1-e6f18b850dfa> in <module>()
     17     pos_i = i / n_col
     18     pos_j = i % n_col
---> 19     df.groupby("cp_data")[col].plot.hist(title=col, alpha=0.5, ax=axes[pos_i, pos_j]);
     20 
     21 

IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
索引器错误回溯(最近一次调用)
在()
17位置i=i/n列
18位置j=i%n柱
--->19 df.groupby(“cp_数据”)[col].plot.hist(title=col,alpha=0.5,ax=axes[pos_i,pos_j]);
20
21
索引器错误:只有整数、片(`:`)、省略号(`…`)、numpy.newaxis(`None`)和整数或布尔数组是有效的索引
为什么绘图历史会导致索引器错误


似乎在某个地方发生了一些错误,如何找出它?

当我运行您的代码示例时,我得到了一个不同的错误:
KeyError:'cp\u data'
。pos\u I和pos\u j必须是整数,因为它们被用作轴的索引。