-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalyze.py
More file actions
42 lines (34 loc) · 1.3 KB
/
Copy pathanalyze.py
File metadata and controls
42 lines (34 loc) · 1.3 KB
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
import sys
import pandas as pd
def analyze(path: str) -> None:
df = pd.read_csv(path)
print(f"=== {path} ===")
print(f"행: {len(df):,} 열: {len(df.columns)}")
print(f"컬럼: {list(df.columns)}\n")
numeric = df.select_dtypes(include="number")
if not numeric.empty:
print("[ 수치형 통계 ]")
stats = numeric.describe().T[["count", "mean", "std", "min", "50%", "max"]]
stats.columns = ["count", "평균", "표준편차", "최솟값", "중앙값", "최댓값"]
print(stats.to_string())
print()
categorical = df.select_dtypes(exclude="number")
if not categorical.empty:
print("[ 범주형 통계 ]")
for col in categorical.columns:
top = df[col].value_counts().head(5)
print(f" {col} (고유값 {df[col].nunique()}개):")
for val, cnt in top.items():
print(f" {val}: {cnt}건")
print()
missing = df.isnull().sum()
missing = missing[missing > 0]
if not missing.empty:
print("[ 결측치 ]")
for col, cnt in missing.items():
print(f" {col}: {cnt}건 ({cnt / len(df):.1%})")
else:
print("[ 결측치 ] 없음")
if __name__ == "__main__":
path = sys.argv[1] if len(sys.argv) > 1 else "data.csv"
analyze(path)