我想清理我的数据,基本上我有我的数据-
数据帧-
d = {'User': ['Mansi kinney', 'Mansi kinney', 'Mansi kinney', 'Alley Huff', 'Alley Huff', 'Alley Huff', Raedden Grip', 'Raedden Grip', 'S.Sarkar',
'S.Sarkar', 'S.Sarkar'],
'Work': ['', '', '', 'College', 'College', 'College', '', '', 'Business', 'Business', 'Business'],
'Country': ['Aus', 'Aus', 'Australia', 'US','US', 'US', 'Ban', 'Ban',
'Ind', 'Ind', 'Ind'],
'Dept': ['Safety', 'Safety', 'Safety', '', '', '', '', '', '', '', ''],
'Training': ['', 'Internal', '', '', 'External', '', '', '', '', 'Internal', ''],
'Status': ['', '', 'Active', '', '', 'Active', '', 'Active', '', '', '']
}
df = pd.DataFrame(data=d)
df
在这里,我想删除更多单元格为空且数据分散的行,因此我想将其放在一行中,并删除不必要的行重复
我的输出应该是-
d = {'User':['Mansi kinney','Alley Huff','Raedden Grip', 'S.Sarkar'],
'Work': ['', 'College', '', 'Business'],
'Country': ['Aus', 'US', 'Ban', 'Ind'],
'Dept': ['Safety', '', '', ''],
'Training':['Internal','External', '', 'Internal'],
'Status':['Active','Active','Active', 'Active']
}
df = pd.DataFrame(data=d)
df
我已经在智能手机上输入了全部内容,请告诉我问题是否清楚。请帮助我清理数据并获得所需的输出。提前感谢
您可以按“用户”分组并使用“”聚合。使用unique()加入并删除重复项:
更新:这是您的完整数据
相关问题 更多 >
编程相关推荐