Menu
Coddy logo textTech

Descriptive Statistics

Lesson 14 of 19 in Coddy's Pandas Analytics course.

Pandas offer several functions that help to understand and analyze the data. Here are a few commonly used functions:

<strong>.count()</strong>: returns the number of non-null observations:

df['column_name'].count()

<strong>.mean()</strong>: returns the mean of the non-null observations:

df['column_name'].mean()

<strong>.min()</strong> and <strong>.max()</strong>: return the minimum and maximum values of non-null observations:

df['column_name'].min()
df['column_name'].max()

<strong>.median()</strong>: Returns the median of the non-null observations:

df['column_name'].median()

<strong>.std()</strong>: Returns the standard deviation of the non-null observations:

df['column_name'].std()

Here is an example of how to use those methods with what we learned:

Count how many players are in group A:

players_a = df[df["group"] == "A"]
num_players = players_a["id"].count()
mean_score = players_a["score"].mean()
challenge icon

Challenge

Easy

The CSV file visits.csv contains information about how many visits were made at a particular location at a particular time.

Here is the first 5 lines of the file:

location_id,visits,timestamp
8,1771,27498
9,4187,79919
0,4959,54228
6,7721,41588

Create a dictionary with the following keys: min, max, mean, std and median and provide the corresponding value of the statistics of the column visits for location id 5.

Finally, print the dictionary.

 

You are provided with part of the code for this challenge, complete the missing.

Try it yourself

# pandas as pd is already imported
df = pd.read_csv("./visits.csv")
# Write your code below


res = {
    "min": locaion_5["visits"].min(),
    "max": # fill
    "mean": # fill
    "std": # fill
    "median": # fill
}
print(res)

All lessons in Pandas Analytics