gpt4 book ai didi

python - 在 Pandas 或 Matplotlib 中绘制图形

转载 作者:太空宇宙 更新时间:2023-11-04 10:30:38 24 4
gpt4 key购买 nike

我的元组列表为 [(2014, 30, 15), (2015, 10, 20), (2007, 5, 3)]。 现在我想在 pandas 中绘制条形图,使 X 轴上每个元组的第一个索引和 y 轴上第二个和第三个元素的相应条形图。因此对于 x 轴上的第一个元组 2014 和 y 轴上分别为 30 和 15 的两个条。如何使用 pandas plot 函数或在 python matplotlib 中实现此目的?

最佳答案

听起来像你想要的:

df = pd.DataFrame( [(2014, 30, 15), (2015, 10, 20), (2007, 5, 3)] )
df.columns = ['year','v1','v2']
df.set_index('year', inplace=True)
df.plot(kind='bar')

给出:

enter image description here

关于python - 在 Pandas 或 Matplotlib 中绘制图形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26894791/

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