
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 –
- How to install plotly python with pip?
- How to create a Line Chart with Plotly Python?
- How to create Scatter plot in Plotly Python?
- How to create a Bar Chart in Plotly Python?
- How to create Horizontal Bar Chart in Plotly Python?
- How to create a Histogram in plotly python?
- How to Create a Box Plot in Plotly Python?
- How to create a Pie Chart in Plotly Python?
- How to create a Dot Plot in Plotly Python?
- How to Create Heatmap with Plotly Python?
- How to Create a Violin Plot in Plotly Python?
- How to Create Subplots in Plotly Python?
- How to Create a Bubble Chart in Plotly Python?
- How to Create a Gantt Chart in Plotly Python?
- How to Create an Area Chart in Plotly Python?