Pandas中groupby后调用boxplot出现KeyError的问题求助
Pandas中groupby后调用boxplot出现KeyError的问题求助
这个非常简单的脚本运行时抛出了如下错误:
KeyError: "None of [Index(['A', 1], dtype='object')] are in the [index]"
脚本代码如下:
import pandas as pd import matplotlib.pyplot as plt L1 = ['A','A','A','A','B','B','B','B'] L2 = [1,1,2,2,1,1,2,2] V = [9.8,9.9,10,10.1,19.8,19.9,20,20.1] df = pd.DataFrame({'L1':L1,'L2':L2,'V':V}) print(df) df.groupby(['L1','L2']).boxplot(column='V') plt.show()
我的DataFrame内容是:
L1 L2 V 0 A 1 9.8 1 A 1 9.9 2 A 2 10.0 3 A 2 10.1 4 B 1 19.8 5 B 1 19.9 6 B 2 20.0 7 B 2 20.1
我期望生成的图表包含四个箱线图来展示V的数值,箱线图的标签应该是A/1、A/2、B/1、B/2。
我已经查阅过相关的问题解决方案,但还是没能修复这个错误,AI工具也没帮上忙。
我到底哪里理解错了呢?
备注:内容来源于stack exchange,提问作者Alessandro Jacopson
相关产品推荐
相关产品推荐

