带有 bolean 列和 Int 值的箱线图

时间:2021-04-15 16:56:37

标签: python dataframe matplotlib seaborn

我想根据电影是否属于戏剧类别或(真或假)来创建变量持续时间分布的箱线图

可惜这两个选项没有考虑in_Dramas列是true还是false...

注意两列在同一个DataFrame中

static lazyInit = false

enter image description here enter image description here

1 个答案:

答案 0 :(得分:0)

对于熊猫箱线图,您可以设置 by='in_drama'column='duree' 以获得 in_drama == Falsein_drama == True 的 x 值,以及考虑 {{1} }列:

duree

seaborn 情节也应该有效。由于只需要一个子图,可以直接使用import matplotlib.pyplot as plt import pandas as pd import seaborn as sns movies = pd.DataFrame({'in_drama': [False, False, False, False, False, True, True, True, True, True], 'durée': [95, 118, 143, 89, 91, 145, 168, 193, 139, 141]}) movies.boxplot(by='in_drama', column='durée', figsize=(7, 7)) plt.show()

sns.boxplot

左边是 pandas boxplot,右边是 seaborn:

pandas vs seaborn boxplot