Note
Pandas (47) 본문
728x90
How to format or suppress scientific notations in a pandas dataframe?
# Input
df = pd.DataFrame(np.random.random(4)**10, columns=['random'])
# 1: Rounding
df.round(4)
# 2: Use apply to change format
df.apply(lambda x: '%.4f' % x, axis=1)
# or
df.applymap(lambda x: '%.4f' % x)
# 3: Use set_option
pd.set_option('display.float_format', lambda x: '%.4f' % x)
# 4: Assign display.float_format
pd.options.display.float_format = '{:.4f}'.format
print(df)
# Reset/undo float formatting
pd.options.display.float_format = None
'Pandas' 카테고리의 다른 글
Pandas (49) (0) | 2022.09.15 |
---|---|
Pandas (48) (0) | 2022.09.14 |
Pandas (46) (0) | 2022.09.12 |
Pandas (45) (0) | 2022.09.11 |
Pandas (44) (0) | 2022.09.10 |
Comments