是否可以指定在破折号数据表中显示的格式化字符串?我有一个包含大量数字的列。我想将它们显示为“123.3K”、“23M”,但仍然能够正确对它们进行排序。
一年前,plotly 论坛上有一个帖子,但结论是“尚无解决方案”。
https://community.plot.ly/t/dash-datatable-formatter-string/6328
你可以这样做:
import dash
import dash_html_components as html
import dash_table
from dash_table.Format import Format, Scheme
import pandas as pd
app = dash.Dash(__name__)
df = pd.DataFrame({"numbers": [123300, 23000000]})
app.layout = html.Div(
[
dash_table.DataTable(
id="typing_formatting_1",
data=df.to_dict("records"),
columns=[
{
"id": "numbers",
"name": "Formatted Numbers",
"type": "numeric",
"format": Format(precision=4, scheme=Scheme.decimal_si_prefix),
},
],
)
]
)
if __name__ == "__main__":
app.run_server()
结果:
来源: