gpt4 book ai didi

python - 带有 Pandas DataFrame 的点图/Ggplot;列名作为 x 值,相应的列值作为 y 值

转载 作者:行者123 更新时间:2023-12-04 01:13:54 25 4
gpt4 key购买 nike

我正在尝试在 Python 中为如下所示的 DataFrame 创建点图/ggplot:

layers_time = {'2 layers': [20.6885, 25.1765, 18.7503, 19.2090, 19.2548],
'3 layers': [20.4360, 27.5285, 20.1958, 18.9536, 20.1673],
'4 layers': [18.1703, 21.9665, 17.0667, 17.3353, 16.2638],
'5 layers': [19.3265, 25.7931, 17.9827, 18.5448, 18.8970],
'6 layers': [19.7180, 24.7097, 20.7460, 19.7300, 18.2760]
}

layers_time = pd.DataFrame(layers_time, columns=['2 layers', '3 layers',
'4 layers', '5 layers', '6 layers'])

我只想让列名成为 x 值,并将它们的对应值作为 y 轴上的点。
此外,是否有一种聪明的方法可以将这些值的平均值包含为具有不同颜色的点?
我试过类似问题的答案,但它们不起作用,因为我的 x 和 y 尺寸不同?

最佳答案

让我们尝试融化数据框,然后用variable作为xvalues作为绘制散点图>y

df=layers_time.melt()#.
plt.scatter(df.variable,df.value)

enter image description here

关于python - 带有 Pandas DataFrame 的点图/Ggplot;列名作为 x 值,相应的列值作为 y 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63977495/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com