gpt4 book ai didi

python - 如何使用电子表格中的两个不同列制作分组条形图?

转载 作者:行者123 更新时间:2023-12-03 08:14:07 24 4
gpt4 key购买 nike

我正在做一个业余项目,但在制作显示州内学费和州外学费的分组条形图时遇到了麻烦。我只能显示其中之一。如何使其并排显示每个学院?

import plotly.express as px
import pandas as pd
import plotly.graph_objects as go
import plotly.io as pio

df = pd.read_csv('college_data.csv')

barchart = px.bar(
data_frame = df,
x = "college_name",
#color = "out-of-state_tuition",
y = "in-state_tuition",
opacity = 0.9,
orientation = "v",
barmode = 'group',
title='Annual In-State Tuition vs Out-of-state Tuition',
)
pio.show(barchart)

仅使用一列的条形图: enter image description here

具有 2 个不同列的电子表格: enter image description here

最佳答案

import numpy as np
df = pd.DataFrame({"college_name":list("ABCD"),"in-state_tuition":np.random.randint(5000,7000,4),"out-of-state_tuition":np.random.randint(8000,15000,4)})

px.bar(
data_frame = df,
x = "college_name",
y = ["in-state_tuition","out-of-state_tuition"],
opacity = 0.9,
orientation = "v",
barmode = 'group',
title='Annual In-State Tuition vs Out-of-state Tuition',
)

enter image description here

关于python - 如何使用电子表格中的两个不同列制作分组条形图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69978250/

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