pandas change e notation to 10 exponent representation
Question:
I have pandas dataframe which has numerical value xxxxe-n like this:
Feature p-value
0 FuzzYEn11 1.915683e-19
1 DimFractal11 2.352654e-18
2 Approx11 2.960694e-15
3 SampEnt11 2.249975e-19
4 D211 7.058137e-17
... ... ...
145 FuzzYEn416 6.374531e-04
146 DimFractal416 2.476636e-18
147 Approx416 2.708140e-05
148 SampEnt416 4.232942e-02
149 D2416 3.184591e-08
Since i want to make a report about this result, due efficiency reason i want all p-value set to 2-decimal round following with 10 exponent just like this:
149 D2416 3.18x10-8
Is there anyway to do this with pandas directly without i edit it manually in word or excel? Thanks
Answers:
use map
with format
and replace
to get the output you want
df['p-value'] = df['p-value'].map('{:0.2e}'.format).replace("e", "*10^",regex=True)
I have pandas dataframe which has numerical value xxxxe-n like this:
Feature p-value
0 FuzzYEn11 1.915683e-19
1 DimFractal11 2.352654e-18
2 Approx11 2.960694e-15
3 SampEnt11 2.249975e-19
4 D211 7.058137e-17
... ... ...
145 FuzzYEn416 6.374531e-04
146 DimFractal416 2.476636e-18
147 Approx416 2.708140e-05
148 SampEnt416 4.232942e-02
149 D2416 3.184591e-08
Since i want to make a report about this result, due efficiency reason i want all p-value set to 2-decimal round following with 10 exponent just like this:
149 D2416 3.18x10-8
Is there anyway to do this with pandas directly without i edit it manually in word or excel? Thanks
use map
with format
and replace
to get the output you want
df['p-value'] = df['p-value'].map('{:0.2e}'.format).replace("e", "*10^",regex=True)