python - Format multiple dataframe columns with the thousand separator -




i able put thousand separator 1 column slice. how multiple columns?

this works:

summary.iloc[:,6]=summary.iloc[:,6].map('{:,}'.format) 

but not:

summary.iloc[:,6]=summary.iloc[:,6:].map('{:,}'.format) 

you're looking df.applymap:

summary.iloc[:, 6:] = summary.iloc[:,6:].applymap('{:,}'.format) 

mvce:

in [1384]: df = pd.dataframe({'col1' : np.random.choice(10000, 10), 'col2' :  np.random.choice(10000, 10)}); df out[1384]:     col1  col2 0  3362  4943 1  7296  1600 2   222  3276 3  8287  8913 4   816  2211 5  8550  9625 6  1020  1453 7  5635  4890 8  4218  3150 9  9601  4744  in [1388]: df.iloc[:, :].applymap('{:,}'.format) out[1388]:      col1   col2 0  3,362  4,943 1  7,296  1,600 2    222  3,276 3  8,287  8,913 4    816  2,211 5  8,550  9,625 6  1,020  1,453 7  5,635  4,890 8  4,218  3,150 9  9,601  4,744 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -