Add a row with means of columns to pandas DataFrame Add a row with means of columns to pandas DataFrame python python

Add a row with means of columns to pandas DataFrame


Use loc for setting with enlargement:

df.loc['mean'] = df.mean()

The resulting output:

       diode1  diode2  diode3  diode4Time                                 0.53      7.0     0.0    10.0    16.01.218    17.0     7.0    14.0    19.01.895    13.0     8.0    16.0    17.02.57      8.0     2.0    16.0    17.03.24     14.0     8.0    17.0    19.03.91     13.0     6.0    17.0    18.04.594    13.0     5.0    16.0    19.05.265     9.0     0.0    12.0    16.05.948    12.0     3.0    16.0    17.06.632    10.0     2.0    15.0    17.0mean     11.6     4.1    14.9    17.5