我无法弄清楚这里有什么问题! 基本上,我正在使用Pandas DataFrame方法df.boxplot绘制2x2箱图,如下所示:
fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(18, 16))
axes = axes.reshape(-1)
for i, crp in enumerate(["Cabbage", "Green beans", "Potato", "Wheat"]):
print i, crp
select = pd.Series(crp)
df[df.Crop.isin(select)].boxplot(
"Total_Irrigation_mm", by="Climate", ax=axes[i])
我在轴上重复绘制白菜,青豆,马铃薯和小麦的情节。它适用于三种作物然后我收到以下错误:
keys, values = zip(*gp_col)
ValueError: need more than 0 values to unpack and the following output
我的数据框,df是:
level_0 index Crop Climate Year Total_Irrigation_mm
0 0 0 Cabbage Humid continental 1981 248
1 1 1 Cabbage Humid continental 1982 257
2 2 2 Cabbage Humid continental 1983 329
3 3 3 Green beans Humid continental 1981 349
4 4 4 Green beans Humid continental 1982 329
5 5 5 Green beans Humid continental 1983 303
6 6 6 Potato Humid continental 1981 278
7 7 7 Potato Humid continental 1982 393
8 8 8 Potato Humid continental 1983 393
9 9 9 Wheat Humid continental 1981 393
10 10 10 Wheat Humid continental 1982 393
11 11 11 Wheat Humid continental 1983 393
12 12 12 Cabbage Temperate 1981 393
13 13 13 Cabbage Temperate 1982 393
14 14 14 Cabbage Temperate 1983 393
15 15 15 Green beans Temperate 1981 393
16 16 16 Green beans Temperate 1982 393
17 17 17 Green beans Temperate 1983 393
18 18 18 Potato Temperate 1981 393
19 19 19 Potato Temperate 1982 393
20 20 20 Potato Temperate 1983 318
21 21 21 Wheat Temperate 1981 312
22 22 22 Wheat Temperate 1982 350
23 23 23 Wheat Temperate 1983 152
24 24 24 Cabbage Subtropical 1981 159
25 25 25 Cabbage Subtropical 1982 157
26 26 26 Cabbage Subtropical 1983 122
27 27 27 Green beans Subtropical 1981 196
28 28 28 Green beans Subtropical 1982 126
29 29 29 Green beans Subtropical 1983 188
30 30 30 Potato Subtropical 1981 123
31 31 31 Potato Subtropical 1982 113
32 32 32 Potato Subtropical 1983 211
33 33 33 Wheat Subtropical 1981 152
34 34 34 Wheat Subtropical 1982 158
35 35 35 Wheat Subtropical 1983 158
Traceback (most recent call last):
File "C:\Users\*\Anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 2883, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-1071-c19c414988ec>", line 7, in <module>
"Total_Irrigation_mm", by="Climate", ax=axes[i])
File "C:\Users\*\Anaconda\lib\site-packages\pandas\core\frame.py", line 4973, in boxplot
**kwds)
File "C:\Users\*\Anaconda\lib\site-packages\pandas\tools\plotting.py", line 2368, in boxplot
ax=ax, layout=layout, return_type=return_type)
File "C:\Users\*\Anaconda\lib\site-packages\pandas\tools\plotting.py", line 2763, in _grouped_plot_by_column
keys, values = zip(*gp_col)
ValueError: need more than 0 values to unpack