:
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