簡體   English   中英

從CSV數據制作直方圖

[英]Make a histogram from csv data

我正在嘗試使用.CSV文件中的數據制作直方圖。 我把下面的代碼放在一起,當我運行它時出現“ int”對象不可迭代的錯誤,有什么想法嗎?

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的文檔字符串,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.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM