I'm doing a side project and I'm having trouble making a grouped bar chart that displays in-state-tuition and out-of-state tuition. I'm only able to display one or the other. How can I make it display both side by side for each college?
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)
Bar chart using only one column:
Spreadsheet with 2 different columns:
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',
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With