Python 从csv数据制作直方图

Python 从csv数据制作直方图,python,pandas,numpy,matplotlib,histogram,Python,Pandas,Numpy,Matplotlib,Histogram,我正在尝试用.CSV文件中的数据制作直方图。我把下面的代码放在一起,当我运行它时,我得到一个int“object is not iterable”错误,有什么想法吗 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

我正在尝试用.CSV文件中的数据制作直方图。我把下面的代码放在一起,当我运行它时,我得到一个int“object is not iterable”错误,有什么想法吗

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

这一行存在一个问题:

plt.hist(year_2017,bins=bins, range = 20)
根据hist的docstring,range必须是元组:


哪一行导致了错误?给我们一个最小的、可复制的示例数据。这样,很难说你的错误发生在哪里!
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.