我有以下数据结构:
data = [
[12, [0.1, 0.2, 0.3, 0.4, 0.5]],
[14, [0.8, 0.7, 0.6, 0.4, 0.2]]
# .... and so on
]
df = pd.DataFrame(data, columns=['index', 'distribution'])如何构建方框图表,其中:
distribution列的分布(使用方框/晶须/离群值),对于每个索引index (例如,如果index值相同,distribution将被合并)g 210聚合分布。
发布于 2022-09-29 07:03:47
你可以使用熊猫的.explode()将讨厌的列表转换成一个长格式的数据格式。到目前为止,Seaborn是从dataframe创建matplotlib风格的盒图的最容易的摇摆。Seaborn将自动将属于同一“索引”的值分组。
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
data = [
[12, [0.1, 0.2, 0.3, 0.4, 0.5]],
[14, [0.8, 0.7, 0.6, 0.4, 0.2]]
# .... and so on
]
df = pd.DataFrame(data, columns=['index', 'distribution'])
sns.boxplot(data=df.explode('distribution'), x='index', y='distribution', palette='magma')

https://stackoverflow.com/questions/73891218
复制相似问题