I am trying to create a plotly table with Python Panda Dataframe using package :import plotly.graph_objs as go I would like to have my panda dataframe rownames as row names in the plotly table. Can this be done the table from dataframe i am not able to have the XXX, YYY, etc as column names. Please help.The table from plotly
3 Answers
import plotly.graph_objects as go
import pandas as pd
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_usa_states.csv')
fig = go.Figure(data=[go.Table(
header=dict(values=list(df.columns),
fill_color='paleturquoise',
align='left'),
cells=dict(values=[df.Rank, df.State, df.Postal, df.Population],
fill_color='lavender',
align='left'))
])
fig.show()
1 Comment
jsta
unlike the other answers this one allows you to change the formatting of individual columns
Not sure what you mean by graph_obj table. However, you can create table using plotly following this:
import plotly.plotly as py
import plotly.figure_factory as ff
import pandas as pd
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/school_earnings.csv")
table = ff.create_table(df)
py.iplot(table, filename='jupyter-table1')
From the link: https://plot.ly/python/ipython-notebook-tutorial/

XXXandYYYin the dataframe that you're trying to put into a table? It doesn't look like that from the screenshot.