-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExploreData.py
46 lines (35 loc) · 1.41 KB
/
ExploreData.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import pandas as pd
import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt
#load unemployment csv to begin EDA
unemployment = pd.read_csv('/Users/mac/Downloads/EDA with Python/clean_unemployment.csv')
print(unemployment.head())
print(unemployment.tail())
print(unemployment.info())
print(unemployment.describe())
print(unemployment['continent'].value_counts())
#create an histogram of unemployment in 2021
sns.histplot(data=unemployment, x="2021", binwidth=1)
plt.title("Unemployment in 2021")
#plt.show()
#Filter our unemployment data for countries whose continent is not oceania
not_oceania = ~unemployment["continent"].isin(["Oceania"])
print(unemployment[not_oceania])
#See the min and max employement rates in 2021
print(unemployment["2021"].min(),unemployment["2021"].max())
#boxplot of unemployment in 2021 by continent
sns.boxplot(data=unemployment, x="2021", y="continent")
plt.title("Unemployment in 2021 by continent")
#plt.show()
#summarise data using groupby and aggregates
print(unemployment.groupby('continent')['2021'].agg(['mean','std']))
continent_summary = unemployment.groupby('continent').agg(
mean_rate_2021 = ('2021','mean'),
std_rate_2021 = ('2021','std')
)
print(continent_summary)
#A barplot showing continents and their average unemployement rate in 2021
sns.barplot(data=unemployment, x='continent', y='2021')
plt.title('Avg unemployment rate by continent in 2021')
plt.show()