【发布时间】:2017-10-22 12:17:18
【问题描述】:
我正在使用 python 3 和 jupyter notebook。我有一个结构如下的熊猫数据框:
location price
Apr 25 ASHEVILLE 15.0
Apr 25 ASHEVILLE 45.0
Apr 25 ASHEVILLE 50.0
Apr 25 ASHEVILLE 120.0
Apr 25 ASHEVILLE 300.0
<class 'pandas.core.frame.DataFrame'>
我只是想为每个位置创建一个箱线图,以显示每个位置的项目之间的价格范围。
当我运行以下代码时:
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
plt.boxplot(postings)
plt.show()
它返回 TypeError: unhashable type: 'slice'
【问题讨论】:
-
你确定
postings是一个数据框吗?尝试只传递列的值而不是整个数据框。 -
这是一个df。当我尝试传递 plt.boxplot(postings.location) 时,它输出 IndexError: 0
标签: python pandas matplotlib boxplot