Python / Data Science Essentials Interview Questions
How do you compute descriptive statistics on a Pandas DataFrame?
Descriptive statistics summarise the central tendency, spread, and shape of a dataset. Pandas df.describe() is the starting point for any exploratory analysis, but knowing the individual methods gives you more precise control.
import pandas as pd
import numpy as np
df = pd.read_csv('housing.csv')
# --- df.describe() ---
# Numeric columns: count, mean, std, min, 25%, 50%, 75%, max
df.describe()
# Include object columns too
df.describe(include='all')
# --- Individual statistics ---
df['price'].mean() # arithmetic mean
df['price'].median() # 50th percentile — robust to outliers
df['price'].mode()[0] # most frequent value (returns Series)
df['price'].std() # standard deviation (ddof=1 by default)
df['price'].var() # variance
df['price'].skew() # skewness: >0 right-skewed, <0 left-skewed
df['price'].kurt() # excess kurtosis (0 = normal dist)
df['price'].quantile(0.90) # 90th percentile
df['price'].quantile([0.25, 0.5, 0.75]) # multiple quantiles
# IQR — interquartile range (robust measure of spread)
Q1, Q3 = df['price'].quantile(0.25), df['price'].quantile(0.75)
IQR = Q3 - Q1
# Outlier detection via IQR fence
lower = Q1 - 1.5 * IQR
upper = Q3 + 1.5 * IQR
outliers = df[(df['price'] < lower) | (df['price'] > upper)]
print(f'{len(outliers)} outliers detected ({len(outliers)/len(df)*100:.1f}%)')
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
