How to change column titles? First column title should say "4-Year" and 2nd column title "2-Year". I tried using label={} but kept getting an error.
df = pd.read_csv('college_data.csv')
df1 = df[df.years > 2]
df2 = df[df.years < 3]
#CUNY College Table
fig = go.Figure(data=[go.Table(
header=dict(values=list(df1[['college_name', 'college_name']]),
fill_color='paleturquoise',
font_color='gray',
align='left',
height = 50,
font=dict(size=26),
),
cells=dict(values=[df1.college_name, df2.college_name],
height = 50,
fill_color='lavender',
align='left',
font=dict(size=20),
))
])
fig.update_layout(title = "CUNY Colleges",
width = 900,
height = 1320,
font_family='Palanquin',
font=dict(size=30),
showlegend = False)
st.plotly_chart(fig)
CodePudding user response:
Change
values=list(df1[['college_name', 'college_name']]),
to
values=["4-year", "2-year"],
e.g.
fig = go.Figure(data=[go.Table(
header=dict(values=["4-year", "2-year"],
...
Calling list
on a pandas DataFrame
returns a list of the column names of that dataframe, so list(df1[['college_name', 'college_name']])
is essentially identical to ['college_name', 'college_name']
.