Issue
I have the following piece of code:
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'),
}
)
But, this outputs the cashflow
column as $95000
but I want it output $95,000
Solution
Prefer use the Styler
instead of the DataFrame
:
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.style.format({'cashflow': '${:,}'}), # <- HERE
)
Output:
Answered By - Corralien
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.