You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Streamlit数据框中设置带千分位的货币列格式?

解决方法

只需修改st.column_config.NumberColumn中cashflow列的format参数,将原有的$%.0f替换为$%,.0f即可实现千分位分隔的货币格式显示。

修改后的完整代码:

import pandas as pd
import streamlit as st

cashflow = pd.DataFrame(data=[
  (2023, 10000),
  (2022, 95000),
  (2021, 90000),
  (2020, 80000),
], columns=['year', 'cashflow'])

st.dataframe(
   data=cashflow,
   column_config={
     'year': st.column_config.NumberColumn(format='%d'),
     'cashflow': st.column_config.NumberColumn(label='cashflow', format='$%,.0f'),
   }
)

说明

Python格式化字符串里,,是千位分隔符标记,加上它之后数字会自动按千位拆分添加逗号;%.0f表示保留0位小数,配合$前缀就能输出$95,000这种符合需求的格式。

内容的提问来源于stack exchange,提问作者pathikrit

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 08:55:59