Pandas How To Uncategorized How to calculate variance in Pandas

How to calculate variance in Pandas

Here’s how to calculate variance in Pandas.
how to calculate variance in Pandas

How to calculate variance in Pandas

To calculate a variance in Pandas just use a var method which Pandas is offering to you.

import pandas as pd

my_df = pd.DataFrame({"my_column1": [9, 2, 3, 5],
                     "my_column2": [3, 7, 6, 4],
                      "my_column3": [4, 8, 8, 8]})

print(f'The variance of columns:\n{my_df.var()}')

The variance of columns:
   my_column1  my_column2  my_column3
0           9           3           4
1          11          10          12
2          14          16          20
3          19          20          28

For more details see the documentation of var function.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post