[英]IndexError: too many indices for array
我是SE DS的新手,所以如果需要编辑我的问题,请告诉我。
data = pd.read_csv('Desktop/dataset.csv')
# Feature 1
feature_1 = data['expenses']
我有一个系列代表我的数据集中的功能列:
feature_1.head()
0 6384.911133
1 5099.380859
2 5501.954590
3 7101.831055
4 5235.987793
Name: expenses, Length: 420, dtype: float64
当我调用feature_1.shape时,它返回(420,)
我有一个图和轴区域设置并绘制:
# Create a figure area with three plots
fig, axes = plt.subplots(1, 3, figsize=(15,4.5))
axes[0, 0].hist(feature_1, bins=5)
然后返回错误IndexError:数组的索引过多
我有点困惑,因为我为另一个可以使用的笔记本设置了相同的设置。 有什么想法吗?
matplotlib.pyplot.subplots
创建一个图形和轴数组。 axes数组的大小取决于您要创建的子图的数量。 自从经过(1, 3)
以来,您将在一行中包含三个图。 因此,您的axiss数组shape
属性对此进行了描述。 例如
>>> from matplotlib import pyplot as plt
>>> import numpy as np
>>> a = np.random.rand(420)
>>> a.shape
(420,)
>>> fig, axes = plt.subplots(1, 3, figsize=(15,4.5))
>>> axes.shape
(1, 3)
>>> fig, axes = plt.subplots(2, 2, figsize=(15,4.5))
>>> axes.shape
(2, 2)
>>> axes[0].hist(feature_1, bins=5) # gives your histogram in the first subplot. If it was 2x2 subplot, the access would have been axes[i, j]
希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.