onemorepoint 2019-02-18
1. 数据集基本信息
df = pd.read_csv()
df.head():前五行;
df.info():
对于非数值型的属性列
df.describe(): 各个列的基本统计信息
df.hist(bins=50, figsize=(20, 15)):统计直方图;
对 df 的每一列进行展示:
train_prices = pd.DataFrame({'price': train_df.SalePrice, 'log(price+1)': np.log1p(train_df.SalePrice)}) # train_prices 共两列,一列列名为 price,一列列名为 log(price+1) train_prices.hist()
2. 数据集拆分
def split_train_test(data, test_ratio=.3): shuffled_indices = np.random.permutation(len(data)) test_size = int(len(data)*test_ratio) test_indices = shuffled_indices[:test_size] train_indices = shuffled_indices[test_size:] return data.iloc[train_indices], data.iloc[test_indices]
3. 数据预处理
>> df['label'] = pd.Categorical(df['label']).codes
>> df = pd.get_dummies(df)
>> df.isnull().sum().sort_values(ascending=False).head() # 填充为 mean 值 >> mean_cols = df.mean() >> df = df.fillna(mean_cols) >> df.isnull().sum().sum() 0