数据挖掘笔记:
数据重构
数据合并
1.使用concat方法:将数据train-left-up.csv和train-right-up.csv横向合并为一张表,并保存这张表为result_up。
list_up = [train_left_up, train_right_up]
result_up = pd.concat(list_up, axis=1)
当axis为默认的0时,是纵向合并dataframe。
2.使用DataFrame自带的方法join方法和append合并dataframe:
resul_up = text_left_up.join(text_right_up)
result_down = text_left_down.join(text_right_down)
result = result_up.append(result_down)
result.head()
3.使用Panads的merge方法和DataFrame的append方法合并dataframe:
result_up = pd.merge(train_left_up, train_right_up, left_index=True, right_index=True)
result_down = pd.merge(train_left_down, train_right_down, left_index=True, right_index=True)
result = result_up.append(result_down)
result.head()
数据聚合与运算
pandas可以用groupby对数据按照某一或某几列进行分组等操作。