df 显示样式

df = pd.DataFrame(
    {
        "订单号": ["0001", "0002", "0003", "0004", "0005"],
        "单价": [1099.5, 8790.0, 12.55, 10999.0, 999.5],
        "数量": [1, 3, 1200, 4, 5],
    }
)

df["总价"] = df["单价"] * df["数量"]
col_format = {
    "单价": "¥{:,.2f}",
    "总价": "¥{:,.2f}",
}
df.style.format(
    col_format
    ).background_gradient(
        subset="总价", cmap="Greens"
    )

 

df = pd.DataFrame(
    {
        "订单号": ["0001", "0002", 
                "0003", "0004", "0005"],
        "单价": [1099.5, 8790.0, 
               12.55, 10999.0, 999.5],
        "数量": [1, 3, 1200, 4, 5],
    }
)

df["总价"] = df["单价"] * df["数量"]
col_format = {
    "单价": "¥{:,.2f}",
    "总价": "¥{:,.2f}",
}

df.style.format(col_format).highlight_min(
    "总价", color="red"
    ).highlight_max(
        "总价", color="lightgreen"
    )

 

 

df = pd.DataFrame(
    {
        "订单号": ["0001", "0002", "0003", "0004", "0005"],
        "单价": [1099.5, 8790.0, 12.55, 10999.0, 999.5],
        "数量": [1, 3, 1200, 4, 5],
    }
)

df["总价"] = df["单价"] * df["数量"]

col_format = {
    "单价": "¥{:,.2f}",
    "总价": "¥{:,.2f}",
}
df.style.format(
    col_format
    ).bar(
        subset="总价", cmap="Wistia"
    )

https://www.cnblogs.com/wang_yb/p/17656039.html

 

posted on 2023-08-25 14:59  小小喽啰  阅读(56)  评论(0编辑  收藏  举报