简体   繁体   中英

How to format pandas data frame using style.format method to round upto 2 decimal places?

I have this dataframe called fb_df and it has a daily_return column which I want to round off up to 2decimal places with a % sign at the end(eg 1.05%).

I have tried multiple options by looking at official docs and other references but it is not working and actually showing no changes in output and at the same time it shows no error while running the cell.

fb_df.style.format({'daily_return':"{:,.0f}%"})

This is an output of an above code, you can see daily_return column

Use either

fb_df.style.format({'daily_return': '{:.2f}%'})

or

fb_df.style.format('{:.2f} %', subset='daily_return') 

See the Notes section in the docs .

(in your screenshot, there seems to be no underline between daily and return )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM