Black Lives Matter. Please consider donating to Black Girls Code today.

How to align table column single row text left or right based on condition?

I want left or right alignment of cell rows based on the condition like this image.

Here is what I’ve tried

import pandas as pd
import numpy as np
import plotly.graph_objects as go

df = pd.DataFrame(np.array(
    [
        ["<b>INCOME STATEMENT</b>", ""],
        ["Revene", "$6952"],
        ["Cost of Goods Sold", "$4028"],
        ["GROSS PROFIT", "$3223"],
        ["OPERATING EXPENSES", "$2312"],
        ["Employee COst", "$2323"]
    ]
), columns=["statement", "result"])

fig = go.Figure(data=[go.Table(
    cells=dict(values=[df.statement, df.result],
               fill_color='#ffffff',
               align=['left', "center"]))
])
fig.layout['template']['data']['table'][0]['header']['fill']['color']='rgba(0,0,0,0)'
fig.show()

but left or right I don’t have any idea. Please help me to create the desired chart.

@srajasingh Unfortunetly the only solution to get the text aligned as in your posted image is to redefine the DataFrame column names with a few spaces as prefixes:

df = pd.DataFrame(np.array(
    [
        ["<b>INCOME STATEMENT</b>", ""],
        ["   Revenue", "$6952"],
        ["   Cost of Goods Sold", "$4028"],
        ["<b>GROSS PROFIT</b>", "$3223"],
        ["<b>OPERATING EXPENSES</b>", "$2312"],
        ["   Employee COst", "$2323"]
    ]
), columns=["statement", "result"])

The corresponding

table looks like un this image:

Thanks for the reply. My teammate also come up with spaces solution using figure_factory but I wanted the best practices to implement this so here I’m. I will pass this information to my team and will add spaces to generate those images.