熊猫数据帧转换

时间:2016-02-16 15:22:11

标签: python pandas

我有一个包含

的数据框
employee_country          employee_branch      employee_email     employee_DOB       employee_mobile         position      salary
x                              a                  null             10/8/92               null                  normal        25000
y                              b                  aaa@aa.com        null               7896458978              experienced    50000

下面的代码将给出两个结果集

a ={'emploee_email':['count'],'employee_mobile_number':['count'],'employee_DOB':['count']}
t = data_df.groupby(['employee_country','employee_branch','position']).position.count().unstack('position').fillna(0)
m = data_df.groupby(['employee_country','employee_branch']).agg(a)

print m将给出

employee_country     employee_branch  count_employee_email    count_employee_dob    count_employee_mobile
   x                      a                0                        1                           0

打印t将给出

employee_country       employee_branch    count_experienced_employee   count_normal_employee   
     x                     a                     0                      1                          

我希望以像

这样的形式加入这两个结果集的形式得到结果
employee_country   employee_branch    count_employee_email   count_employee_dob   count_normal_employee   count_experienced_employee
     x                    a                 0                          1                       1                        0

null值不可数

0 个答案:

没有答案