I have a Pandas DataFrame with both float values and integers. I want the integers to be printed with a comma thousands separator and floats rounded to two decimal places. Below is an excerpt of my DataFrame with floats rounded but without the comma thousands separator.
pd.set_option('display.float_format', lambda x: '%.2f' % x)
pd.DataFrame(d)
null_n datatype col_min col_mean col_median col_max col_std
assetCode 0 object nan nan nan nan nan
assetName 0 category nan nan nan nan nan
close 0 float64 0.07 39.71 30.30 1578.13 42.29
open 0 float64 0.01 39.71 30.29 9998.99 42.61
The dataframe is built from multiple Pandas.Series: null_n
, datatype
, col_min
, etc. So I thought I could either 1. convert the integer Series into a string with columns, or 2. alter the way the Pandas dataframe is printed. I don't know how to do 1. or 2. I have seen:
print '{:,}'.format(n)
import locale
locale.setlocale(locale.LC_ALL, '')
locale.format('%d', 1000000, 1)
but neither works for my use case.