feat: 初始化电信客户流失分析项目,完成数据读取和基础清洗

This commit is contained in:
柘黎思 2026-01-12 14:02:27 +08:00
commit b77ff15e43
3 changed files with 7067 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
.venv/
__pycache__/
*.pyc
results/

File diff suppressed because it is too large Load Diff

19
src/main.py Normal file
View File

@ -0,0 +1,19 @@
import polars as pl
data_path = "C:/Users/s1313/Desktop/telco_churn_analysis/data/WA_Fn-UseC_-Telco-Customer-Churn.csv"
try:
df = pl.read_csv(data_path)
# 仅当TotalCharges是字符串类型时才处理
if df["TotalCharges"].dtype == pl.Utf8:
df = df.with_columns(
pl.col("TotalCharges").str.replace(" ", "0").cast(pl.Float64, strict=False)
)
print("✅ 数据处理完成!")
print(f"TotalCharges类型{df['TotalCharges'].dtype}")
print("\n前2行预览")
print(df.head(2))
except Exception as e:
print(f"❌ 操作失败:{e}")