Hello,
I am using the Pandas Styler style.format() method to deal with a currency column. Sample code and format is :
import pandas as pd
df = pd.DataFrame({'quantity':[2, 45, 322],
'unit_cost': [1005.00, 1.92, 0.50]})
df['cost'] = df['quantity'].multiply(df['unit_cost'])
formats = (
{
'quantity': "{:,.0f}".format,
'unit_cost': "$ {:,.2f}".format,
'cost': "$ {:,.2f}".format,
}
)
dfs = df.style.format(formats)
And the resulting styled dataframe is:
However, I'm looking for more of an accounting look where the $ (dollar sign) is justified and aligned left such as this:
Any suggestions on how to write the format to achieve this would be appreciated. Thank you.
Tyler
Solved! Go to Solution.
python - Accounting formatting in Pandas df - Stack Overflow should do it
python - Accounting formatting in Pandas df - Stack Overflow should do it