Easy way to add thousand separator to numbers in Python pandas DataFrame

后端 未结 5 412
感动是毒
感动是毒 2021-01-14 08:36

Assuming that I have a pandas dataframe and I want to add thousand separators to all the numbers (integer and float), what is an easy and quick way to do it?

5条回答
  •  星月不相逢
    2021-01-14 08:57

    Assuming you just want to display (or render to html) the floats/integers with a thousands separator you can use styling which was added in version 0.17.1:

    import pandas as pd
    df = pd.DataFrame({'int': [1200, 320], 'flt': [5300.57, 12000000.23]})
    
    df.style.format('{:,}')
    

    To render this output to html you use the render method on the Styler.

提交回复
热议问题