1

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

2
  • Please include a sample data, and also what you precisely did (the code). This will increase the chances of you getting a quick and correct answer. Thanks. Commented May 16, 2018 at 8:44
  • @Sushmita Are XXX and YYY in the dataframe that you're trying to put into a table? It doesn't look like that from the screenshot. Commented Oct 4, 2019 at 7:51

3 Answers 3

2
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()

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

unlike the other answers this one allows you to change the formatting of individual columns
2

Install this library to generate image from graph.

pip install kaleido

Script:

import plotly.figure_factory as ff
import pandas as pd


fig = ff.create_table(df)
fig.show()
fig.write_image("myimage.png")

Comments

0

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/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.