我在一个数据框中有两列'名字'和'首选名称'。如果首选名称与名字不同,我想将该值移动到名字。 e.g:
First Name Preferred Name
1 David Dave
2 John John
3 Sarah Sarah
4 Elizabeth Liz
First Name Preferred Name
1 Dave Dave
2 John John
3 Sarah Sarah
4 Liz Liz
答案 0 :(得分:0)
Intent intent = new Intent( SplashScreen.this, MainActivity.class);
答案 1 :(得分:0)
最简单的只是指定为EdChum:
df['first name'] = df['preferred name']
print (df)
first name preferred name
1 Dave Dave
2 John John
3 Sarah Sarah
4 Liz Liz
您可以先在差异中创建boolean
掩码,然后按loc
或mask
添加新值:
mask = df['first name'] != df['preferred name']
df.loc[mask, 'first name'] = df['preferred name']
print (df)
first name preferred name
1 Dave Dave
2 John John
3 Sarah Sarah
4 Liz Liz
另一种解决方案:
mask = df['first name'] != df['preferred name']
df['first name'] = df['first name'].mask(mask,df['preferred name'])
print (df)
first name preferred name
1 Dave Dave
2 John John
3 Sarah Sarah
4 Liz Liz