数据重构学习笔记

1.数据的合并,融合(concat and merge)

书中对两类函数的定义如下:

concat函数用法: 1. list_up = [text_left_up,text_right_up]
                     result_up = pd.concat(list_up,axis=1)
                 

                    2.list_down=[text_left_down,text_right_down]
                       result_down = pd.concat(list_down,axis=1)
                       result = pd.concat([result_up,result_down])

                    3.join和append的用法:

                    resul_up = text_left_up.join(text_right_up)
                    result_down = text_left_down.join(text_right_down)
                    result = result_up.append(result_down)
                    4.merge函数的用法:

                    result_up = pd.merge(text_left_up,text_right_up,left_index=True,right_index=True)
                    result_down =    pd.merge(text_left_down,text_right_down,left_index=True,right_index=True)
result = resul_up.append(result_down)
 

 其中红色部分均与concat函数的功能相同

Python 中的groupby函数

groupby函数的用途:对数据进行按类分组,然后合并计算,示意图如下

 groupby函数的用法(以书上的用法解析)

 

1.创建一个表格

2.书中想要把吸烟者和不吸烟者分别归类。使用.groupby('smoker').apply(‘top’),(注意:apply(top)的作用类似于.concat,将每行连接,按照原始数据的等级进行排列)结果如下:

 

3.groupby函数同样可以对多个变量同时进行归类。用法如下

以上为groupby函数的基本用法 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值