1

I'm trying to calculate the mean of a column in the data frame.

I played with two approaches: 1. converting column to an array and calculating mean using numpy.mean() 2. used pandas.mean() on the column itself However they return different values.

import numpy as np
col1= subdf['V12']
col1=np.array(col1)
col1_mean= col1.mean()
col1_mean

This returns: -1.2549951995448174e-15

import numpy as np
col1= subdf['V12']
col1_mean= col1.mean()
col1_mean

This returns: -1.81065810647492e-15

Why are the two means different?

Nayak S
  • 428
  • 1
  • 5
  • 18
  • Could you provide an example Series which demonstrates this? (Perhaps try from your Series and split it (left and right) and see if still occurs etc.) – Andy Hayden Jul 16 '19 at 05:20
  • 3
    Possible duplicate of [mean from pandas and numpy differ](https://stackoverflow.com/questions/53042250/mean-from-pandas-and-numpy-differ) – help-ukraine-now Jul 16 '19 at 07:24
  • It is explained in the question marked by @politicalscientist. Clearly from the values, it is a roundup error. Try comparing `subdf['V12'].apply(np.mean)` with `np.array(..).mean()` – Tarifazo Jul 16 '19 at 15:09

0 Answers0