How to Create Tables in Plotly Python?

Spread the love

To create a Table in Plotly Python, we can use the go.Table function. go.Table provides a Table object for detailed data viewing. The data are arranged in a grid of rows and columns. Most styling can be specified for header, columns, rows or individual cells.

Basic Table –

Let’s create a basic table which shows marks of students.

import plotly.graph_objects as go

fig = go.Figure(data=[go.Table(header=dict(values=['Name', 'Marks']),
                 cells=dict(values=[['Eleven','Mike','Dustin','Max','Lucas'], 
                                    [95, 80, 75, 85, 80]]))])
fig.show()

Styled Table –

We can also style the table.

fig = go.Figure(data=[go.Table(
    header=dict(values=['Name', 'Marks'],
               line_color='darkslategray',
               fill_color='seagreen',
               align='left'),
    cells=dict(values=[['Eleven','Mike','Dustin','Max','Lucas'],
                       [95, 80, 75, 85, 80]],
              line_color='darkslategray',
              fill_color='lightcyan',
              align='left'))
    ])
fig.show()

Create a Table from Pandas DataFrame –

Let’s read a dataframe and see how to create a table from it.

import pandas as pd
url = 'https://raw.githubusercontent.com/bprasad26/lwd/master/data/clothing_store_sales.csv'
df = pd.read_csv(url)
df.head()

Now, Let’s visualize this dataframe in plotly table.

fig = go.Figure(data=[go.Table(
    header=dict(values=list(df.columns),
                fill_color='seagreen',
                align='left'),
    cells=dict(values=[df['Customer'], df['Type of Customer'], df['Items'], 
                       df['Net Sales'], df['Method of Payment'],
                      df['Gender'],df['Marital Status'], df['Age']],
               fill_color='lightcyan',
               align='left'))
])
fig.show()

Related Posts –

  1. How to install plotly python with pip?
  2. How to create a Line Chart with Plotly Python?
  3. How to create Scatter plot in Plotly Python?
  4. How to create a Bar Chart in Plotly Python?
  5. How to create Horizontal Bar Chart in Plotly Python?
  6. How to create a Histogram in plotly python?
  7. How to Create a Box Plot in Plotly Python?
  8. How to create a Pie Chart in Plotly Python?
  9. How to create a Dot Plot in Plotly Python?
  10. How to Create Heatmap with Plotly Python?
  11. How to Create a Violin Plot in Plotly Python?
  12. How to Create Subplots in Plotly Python?
  13. How to Create a Bubble Chart in Plotly Python?
  14. How to Create a Gantt Chart in Plotly Python?
  15. How to Create an Area Chart in Plotly Python?

Rating: 1 out of 5.

Leave a Reply