I have a csv file which is below
ID,Name1,Name2
1,A,A
2,B,B
3,C,D
4,0,F
5,0,Z
The new table is below
ID,NewName
1,A
2,B
3,C
4,F
5,Z
Basically if 0
coming in the Name1
has to replace with Name2
I have a csv file which is below
ID,Name1,Name2
1,A,A
2,B,B
3,C,D
4,0,F
5,0,Z
The new table is below
ID,NewName
1,A
2,B
3,C
4,F
5,Z
Basically if 0
coming in the Name1
has to replace with Name2
You can use replace
then do bfill
df['Name']=df.drop('ID',1).replace({'0':np.nan}).bfill(1).iloc[:,0]
df
ID Name1 Name2 Name
0 1 A A A
1 2 B B B
2 3 C D C
3 4 0 F F
4 5 0 Z Z