Skip to content

Instantly share code, notes, and snippets.

@audhiaprilliant
Created November 2, 2022 14:37
Show Gist options
  • Select an option

  • Save audhiaprilliant/90ef0f5d0e12e28a27a00eb9da2c704b to your computer and use it in GitHub Desktop.

Select an option

Save audhiaprilliant/90ef0f5d0e12e28a27a00eb9da2c704b to your computer and use it in GitHub Desktop.
Matplotlib 101 - Basic Introduction for Python Beginner
# ---------- IMPORT PACKAGES ----------
# Dataframe manipulation
import pandas as pd
# Matrices operation
import numpy as np
# Data viz with matplotlib
import matplotlib
import matplotlib.pyplot as plt
from matplotlib import style
# Check packages' version
print('pandas ', pd.__version__)
print('numpy ', np.__version__)
print('matplotlib ', matplotlib.__version__)
print('seaborn ', sns.__version__)
# ---------- LOAD DATA SET ----------
# Load the data set into Python
df = pd.read_csv(filepath_or_buffer = 'data/WA_Fn-UseC_-Telco-Customer-Churn.csv', sep = ';')
# Print top 5 rows
df.head(n = 5)
# Metadata
df.info()
# Change column types
df = df.astype({'SeniorCitizen': object})
# ---------- DATA PREPARATION ----------
# Number of missing values in a data frame
df.isnull().sum()
# Summary statistics
df.describe()
# Check the unique values of categorical columns
for col in df.select_dtypes('object').columns:
print(df[str(col)].value_counts(), '\n')
# Data aggregation
df_group_1 = df.groupby('PaymentMethod')[['customerID']].count().reset_index()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment