import os
import pandas as pd
# 添加 测试数据
os.makedirs(os.path.join('.', 'data'), exist_ok=True)
data_file = os.path.join('.', 'data', 'house_tiny.csv')
with open(data_file, 'w') as f:
f.write('NumRooms,Alley,Test,Price\n')
f.write('NA,Pave,NA,127500\n')
f.write('2,D,A,106000\n')
f.write('4,NA,NA,178100\n')
f.write('NA,NA,B,14000\n')
# 读取 csv 数据
data = pd.read_csv(data_file)
print("\nCSV data => \n", data)
print("-" * 60)
# 检测缺失值
res_null = pd.isnull(data)
print("\nres_null => \n", res_null)
print("\nres_null.sum() => \n", res_null.sum())
# 通过位置索引iloc,将 data 分成 inputs、 outputs
inputs, outputs = data.iloc[:, 0:3], data.iloc[:, 3]
print("-" * 60)