我在python panda DataFrame中有以下数据。我希望有类似于https://stanford.edu/~mwaskom/software/seaborn/examples/grouped_boxplot.html中的分组箱线图
对于每个id,我想有两个箱形图并排绘制。我如何实现这一点。我试图绘制它与海运包,但没有任何成功。
id predicted real
1 [10, 10, 10] [16, 18, 20]
2 [12, 12, 15] [15, 17, 19, 21, 23]
3 [20, 5, 4, 4] [29, 32]
4 [25, 25, 25, 24, 21] [21, 24, 25, 26, 28, 29, 30, 33]
5 [20, 20, 20, 21] [21, 22, 24, 26, 28, 30, 31, 32]
6 [8, 3, 3, 14] [25, 27]
7 [1, 4, 4, 4, 5, 6, 10] [69, 71, 72]
8 [11, 11, 11, 11] [19, 21, 22, 23, 24]
9 [7, 6, 9, 9] [19, 26, 27, 28]
10 [30, 30, 30, 30, 30] [38, 39]
字符串
2条答案
按热度按时间dy1byipe1#
请注意您正在查看的示例中的表结构
字符串
的数据
型
的
我们的目标是把你的table摆成这样
设置
型
的
获取正确格式的表格
型
的
型
zpqajqem2#
print(type(df.loc[0, 'predicted']))
将确认列中的值是list type
。如果它们是string type
,则参见Pandas DataFrame stored list as string: How to convert back to listlist type
的pandas列,最简单的方法是将列pandas.DataFrame.melt
转换为长格式,将列表pandas.DataFrame.explode
转换为单独的值。sns.catplot
和kind='box'
创建figure-level
图,而this answer创建axes-level
图。*在
python 3.12.0
、pandas 2.1.2
、matplotlib 3.8.1
、seaborn 0.13.0
中测试字符串
的数据
df
型
dfm
型