is there a way to keep scientific notation consistent in txt file and after reading it to pandas dataframe.
pd.read_csv(physio_files[1], sep=" ", header = None)
above command is suppressing scientific notation.
is there a way to keep scientific notation consistent in txt file and after reading it to pandas dataframe.
pd.read_csv(physio_files[1], sep=" ", header = None)
above command is suppressing scientific notation.
Consider the dataframe df
df = pd.DataFrame(1000000., range(5), range(5))
print(df)
0 1 2 3 4
0 1000000.0 1000000.0 1000000.0 1000000.0 1000000.0
1 1000000.0 1000000.0 1000000.0 1000000.0 1000000.0
2 1000000.0 1000000.0 1000000.0 1000000.0 1000000.0
3 1000000.0 1000000.0 1000000.0 1000000.0 1000000.0
4 1000000.0 1000000.0 1000000.0 1000000.0 1000000.0
You can control the formatting using pandas 'displat.float_format'
option. You can also assume a value for that option temporarily using pd.option_context
Use '{:0.4e}'.format
as your custom formatter. Change the 4
to suit your needs.
with pd.option_context('display.float_format', '{:0.4e}'.format):
print(df)
0 1 2 3 4
0 1.0000e+06 1.0000e+06 1.0000e+06 1.0000e+06 1.0000e+06
1 1.0000e+06 1.0000e+06 1.0000e+06 1.0000e+06 1.0000e+06
2 1.0000e+06 1.0000e+06 1.0000e+06 1.0000e+06 1.0000e+06
3 1.0000e+06 1.0000e+06 1.0000e+06 1.0000e+06 1.0000e+06
4 1.0000e+06 1.0000e+06 1.0000e+06 1.0000e+06 1.0000e+06