Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display Scientific Notation for certain Columns only, Pandas Dataframe

I am trying to display results from a pandas dataframe, that contains small numbers.

dict1 = {
    'Name':['one', 'two', 'three', 'four'],
    'R1 (V)':[1.1,2.2,3.3,4.4],
    'R2 (mV)':[1.1e-3,2.2e-3,3.3e-3,4.4e-3],
    'R3 (uV)':[1.1e-6,2.2e-6,3.3e-6,4.4e-6],
    'R4 (nV)':[1.1e-9,2.2e-9,3.3e-3,4.4e-9],
    'R5 (pV)':[1.1e-12,2.2e-12,3.3e-12,4.4e-12]
}

df = pd.DataFrame.from_dict(dict1)

Output Data Frame

In my example here I want to change R3 to scientific notation (1.1e-6, 2.2e-6, ...) without changing how the other columns are displayed

like image 531
DavidMul Avatar asked Oct 26 '25 17:10

DavidMul


1 Answers

try to edit the format of your DataFrame like this:

df.style.format({'R3 (uV)': "{:.2E}"})

this will output the DataFrame with R3 in the scientific notation, but if you try to display the DataFrame again you will have to repeat this procedure because the format is not permanent

like image 192
Flavio Moraes Avatar answered Oct 28 '25 07:10

Flavio Moraes