在pandas中,一个groupby,然后是BoxPlot给出键盘:“ [index]中没有一个[index(['a',1],dtype ='object')]

问题描述 投票:0回答:1
这个非常简单的脚本给出了错误:

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

我希望有一个带有四个箱形图的情节显示值v,箱图的标签应为a/1,a/2,b/1,b/2。
i我看了如何解决keyError:u“没有[index([..],dtype ='object')]在[列]中”

但是我无法解决我的错误,AI工具也没有帮助我。

我不理解什么?

您也可以使用

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

进行分组
python pandas group-by boxplot
1个回答
0
投票
boxplot


    

enter image description here

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.