Adel
Adel

Reputation: 3743

Pandas - mean of a data frame only returns the mean of the first column

here is my code:

df = pd.read_csv("aps.csv")
df.replace('na', np.NaN, inplace=True)
print (df.mean(axis=0))

I expect the mean of each column, but it returns only the mean of the first column! why?

aa_000    59336.499567
dtype: float64

Upvotes: 1

Views: 55

Answers (2)

BENY
BENY

Reputation: 323226

You can try na_values

pd.read_csv(r"test.csv",na_values ='na')

Upvotes: 3

piRSquared
piRSquared

Reputation: 294258

I'm guessing that other columns are dtype object

Try:

df.apply(pd.to_numeric, errors='coerce').mean()

Upvotes: 3

Related Questions