Plotting two columns of dataFrame in seaborn

前端 未结 1 1183
没有蜡笔的小新
没有蜡笔的小新 2020-12-10 03:39

I\'m trying to create a bar chart in seaborn that displays values for two variables(Weight, Variance) for each row (Factor) in my data frame. Here is what my data looks like

1条回答
  •  时光说笑
    2020-12-10 04:17

    Aside from cleaning up your data into a tidy format, you need to reformat the text data (percentages) into numeric data types. Since that has nothing to do with barplots, I'll assume you can take care of that on your own and focus on the plotting and data structures instead:

    df = pandas.DataFrame({
        'Factor': ['Growth', 'Value'],
        'Weight': [0.10, 0.20],
        'Variance': [0.15, 0.35]
    })
    fig, ax1 = pyplot.subplots(figsize=(10, 10))
    tidy = df.melt(id_vars='Factor').rename(columns=str.title)
    seaborn.barplot(x='Factor', y='Value', hue='Variable', data=tidy, ax=ax1)
    seaborn.despine(fig)
    

    0 讨论(0)
提交回复
热议问题