我有一个pandas数据框,它由两个带值的列组成。有些值丢失了,我想创建第三列来标记这两列中是否都缺少值或其中一列是否已填充。我不确定如何做到这一点,因为我是新的任何帮助,你可以提供将不胜感激
#input
df = {'First': ['','','A','B','B','C'],
'Second': ['12', '', '10', '', '', '11']}
df = pd.DataFrame(data = d)
#Possible output of third column
df['Third'] = ['Secondfilled', 'missing', 'bothfilled', 'Firstfilled', 'Firstfilled', bothfilled']
您可以将
apply()
与查找dict一起使用一行解决方案,没有ifelse或自定义函数。 根据@SeaBean的建议进行改进
输出:
相关问题 更多 >
编程相关推荐