0

I'm trying to make a histogram with data from a .CSV file. I put together the code below and I'm getting an ''int' object is not iterable' error when I run it, any ideas?

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

file = "...sp histo.csv"
data = pd.read_csv(file)

year_2016 = np.array(data['2016'])
year_2017 = list(np.array(data['2017']))

small_ret = min(min(year_2016),min(year_2017))
large_ret = max(max(year_2016),max(year_2017))
bins = np.arange(small_ret, large_ret, 0.1)

plt.hist(year_2017,bins=bins, range = 20)
plt.show()
2
  • 1
    Which line is causing the error?
    – user8651755
    Commented Dec 21, 2017 at 22:59
  • 1
    give us a minimal, reproduceable example data. This way, hard to say where your error is occuring!
    – i.n.n.m
    Commented Dec 21, 2017 at 23:06

1 Answer 1

1

There is a problem in this line:

plt.hist(year_2017,bins=bins, range = 20)

According to the docstring for hist, range must be a tuple:

range : tuple or None, optional
    The lower and upper range of the bins. Lower and upper outliers
    are ignored. If not provided, `range` is (x.min(), x.max()). Range
    has no effect if `bins` is a sequence.

    If `bins` is a sequence or `range` is specified, autoscaling
    is based on the specified bin range instead of the
    range of x.

Not the answer you're looking for? Browse other questions tagged or ask your own question.