to. 익명의 휀걸

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from scipy import stats

# ggplot 이라는 스타일 적용 => 바탕 회색 격자됨로 바뀜
plt.style.use('ggplot')

df = pd.read_excel("Online Retail.xlsx")
df

✅ 결측치 처리

df.shape

image.png

# 결측치 몇 개 있는지 확인
df.isnull().sum()

image.png

# 결측치 처리 -> CustomerID 컬럼 한정해서 결측치 처리
df = df.dropna(subset=["CustomerID"])
# 결측치 처리 잘 됐나 다시 확인
df.isnull().sum()

image.png

# 매출액 컬럼 생성 (매출 = 수량 * 가격)
df["Sales"] = df["Quantity"] * df["UnitPrice"]
df
# Quantity 컬럼의 고유한 값 
df["Quantity"].unique()

image.png

# 반품(Quantity 음수) 제거 & 제거 확인
df = df[df["Quantity"] > 0]
df["Quantity"].unique()