Gefeliciteerd

Exploratory Data Analysis in Python

George Boorman

Curriculum Manager, DataCamp

Inspectie en validatie

een histogram van boekbeoordelingen

books["year"] = books["year"].astype(int)
books.dtypes
name       object
author     object
rating    float64
year        int64
genre      object
dtype: object
Exploratory Data Analysis in Python

Aggregatie

books.groupby("genre").agg(
    mean_rating=("rating", "mean"),
    std_rating=("rating", "std"),
    median_year=("year", "median")
)
|  genre      | mean_rating | std_rating | median_year |
|-------------|-------------|------------|-------------|
|   Childrens |    4.780000 |   0.122370 |      2015.0 |
|     Fiction |    4.570229 |   0.281123 |      2013.0 |
| Non Fiction |    4.598324 |   0.179411 |      2013.0 |
Exploratory Data Analysis in Python

Ontbrekende data aanpakken

print(salaries.isna().sum())
Working_Year            12
Designation             27
Experience              33
Employment_Status       31
Employee_Location       28
Company_Size            40
Remote_Working_Ratio    24
Salary_USD              60
dtype: int64
Exploratory Data Analysis in Python

Ontbrekende data aanpakken

  • Ontbrekende waarden verwijderen

 

  • Imputeren: gemiddelde, mediaan, modus

 

  • Imputeren per subgroep

 

salaries_dict = salaries.groupby("Experience")["Salary_USD"].median().to_dict()
salaries["Salary_USD"] = salaries["Salary_USD"].fillna(salaries["Experience"].map(salaries_dict))
Exploratory Data Analysis in Python

Categorische data analyseren

salaries["Job_Category"] = np.select(conditions, 
                                     job_categories, 
                                     default="Other")

Staafdiagram met het aantal banen per categorie

Exploratory Data Analysis in Python

Lambda-functies toepassen

Een lambda-functie toepassen

salaries["std_dev"] = salaries.groupby("Experience")["Salary_USD"].transform(lambda x: x.std())
Exploratory Data Analysis in Python

Uitschieters aanpakken

sns.boxplot(data=salaries,
            y="Salary_USD")
plt.show()

Boxplot van salarissen van dataprofessionals, met het 25e percentiel onderaan de box, het 50e percentiel als middenlijn en het 75e percentiel bovenaan

Exploratory Data Analysis in Python

Patronen in de tijd

sns.lineplot(data=divorce, x="marriage_month", y="marriage_duration")
plt.show()

Lijndiagram van de relatie tussen huwelijksmaand en huwelijksduur

Exploratory Data Analysis in Python

Correlatie

sns.heatmap(divorce.corr(numeric_only=True), annot=True)
plt.show()

Een heatmap van correlaties rond echtscheiding

Exploratory Data Analysis in Python

Verdelingen

sns.kdeplot(data=divorce, x="marriage_duration", hue="education_man", cut=0)
plt.show()

KDE van huwelijksduur met hue op education_man en cut gelijk aan nul

Exploratory Data Analysis in Python

Kruistabel

pd.crosstab(planes["Source"], planes["Destination"],
            values=planes["Price"], aggfunc="median")
Destination  Banglore   Cochin   Delhi  Hyderabad  Kolkata  New Delhi
Source                                                               
Banglore          NaN      NaN  4823.0        NaN      NaN    10976.5
Chennai           NaN      NaN     NaN        NaN   3850.0        NaN
Delhi             NaN  10262.0     NaN        NaN      NaN        NaN
Kolkata        9345.0      NaN     NaN        NaN      NaN        NaN
Mumbai            NaN      NaN     NaN     3342.0      NaN        NaN
Exploratory Data Analysis in Python

pd.cut()

Geef de bins op

planes["Price_Category"] = pd.cut(planes["Price"],
                                  labels=labels,
                                  bins=bins)
Exploratory Data Analysis in Python

Data snooping

Heatmap met correlatiecoëfficiënten per aantal tussenstops

Exploratory Data Analysis in Python

Hypotheses genereren

sns.barplot(data=planes, x="Airline", y="Duration")
plt.show()

Staafdiagram van duur versus luchtvaartmaatschappij

Exploratory Data Analysis in Python

Volgende stappen

 

 

 

Exploratory Data Analysis in Python

Gefeliciteerd!

Exploratory Data Analysis in Python

Preparing Video For Download...