How to Calculate Column Average or Mean in Pandas?

Spread the love

Problem –

You want to calculate the average or mean of a column in pandas.

Solution –

Read a dataset to work with.

import pandas as pd

url = 'https://raw.githubusercontent.com/bprasad26/lwd/master/data/Restaurant.csv'
df = pd.read_csv(url)
df.head()

Now if I want to calculate the average or mean of the Meal Price column, I will simply select the this column and call .mean() on it.

df['Meal Price ($)'].mean()
output - 25.89666666666667

Rating: 1 out of 5.

Leave a Reply