2

I am new to SE DS so please let me know if I need to edit my question.

data = pd.read_csv('Desktop/dataset.csv')

# Feature 1
feature_1 = data['expenses']

I have a series representing a feature column from my dataset:

feature_1.head()

0      6384.911133
1      5099.380859
2      5501.954590
3      7101.831055
4      5235.987793

Name: expenses, Length: 420, dtype: float64

When I call feature_1.shape it returns (420, )

I have a figure and axes area set up and plot:

# 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)

It then returns the error IndexError: too many indices for array

I am a little confused of what the probelm might be here becuase I have the same set up for another notebook that works. Any thoughts?

QFII
  • 71
  • 9
  • Do you have your notebook and this code set up in different virtual environments? Package versions might be a cause. – HFulcher Feb 22 '19 at 22:39
  • Can you show a more extension portion of your code (especially before you call the plot function)? –  Feb 23 '19 at 01:41
  • I have updated my code, is this better now? –  Feb 23 '19 at 02:48

1 Answers1

0

matplotlib.pyplot.subplots creates a figure and axes array. The size of the axes array is dependent on the number of subplots you are creating. Since you went by (1, 3), you will be having three plots in a single row. So your axes array shape attribute describes this. For example

>>> 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]

Hope this helps.

Kiritee Gak
  • 137
  • 1
  • 7