Skip to content

Instantly share code, notes, and snippets.

@rohithteja
Created March 11, 2022 14:41
Show Gist options
  • Save rohithteja/a88705aa0ee46aca5acb95ed3548c780 to your computer and use it in GitHub Desktop.
Save rohithteja/a88705aa0ee46aca5acb95ed3548c780 to your computer and use it in GitHub Desktop.
Plotly table
df_scrape["color"] = df_scrape["% Change"].map(lambda x:'red' if x<0 else 'green')
cols_to_show = ['Name','Token', 'Price', '% Change', 'Market Cap']
# to change color of "% change" column
fill_color = []
n = len(df_scrape)
for col in cols_to_show:
if col!='% Change':
fill_color.append(['black']*n)
else:
fill_color.append(df_scrape["color"].to_list())
# Plotly Table
data=[go.Table(columnwidth = [20,15,15,15,15],
header=dict(values=[f"<b>{col}</b>" for col in cols_to_show],
font=dict(color='white', size=20),
height=30,
line_color='black',
fill_color='dimgrey',
align=['left','left', 'right','right','right']),
cells=dict(values=df_scrape[cols_to_show].values.T,
fill_color=fill_color,
font=dict(color='white', size=20),
height=30,
line_color='black',
align=['left','left', 'right','right','right']))]
fig = go.Figure(data=data)
fig.update_layout(go.Layout(xaxis = {'showgrid': False},
yaxis = {'showgrid': False}))
fig.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment