I have a really large df.
UserID Name TempName
Matt 458488 None
Matt 458488 None
Matt 458488 None
Matt 458488 None
Matt 458488 None
Pablo 213123 8748
Pablo 213123 8748
Pablo 213123 8748
Pablo 213123 8748
Pablo 213123 8748
Pablo 213123 8748
Pablo 213123 8748
Kate 2442 None
... ... ...
Need to replace None
in tempName
by Name
Values. But only there where users has None
in Temp
Val. If User
as Pablo in Temp != None
, should pass and tempValue should be unchanged.
None is a string, no NaN
Example result of TempName:
UserID Name TempName
Matt 458488 458488
Matt 458488 458488
Matt 458488 458488
Matt 458488 458488
Matt 458488 458488
Pablo 213123 8748
Pablo 213123 8748
Pablo 213123 8748
Pablo 213123 8748
Pablo 213123 8748
Pablo 213123 8748
Pablo 213123 8748
Kate 2442 2442
... ... ...
Now my code works on simple but really slow loop and if.
For record in df:
if df.TempName.iloc[record] == 'None':
df.TempName.iloc[record] = df.Name.iloc[record]
else:
pass
I looking for faster an maybe better solution of this problem. Maybe someone have a better idea? On SO i found only a solution of merging or concat whole cols, I need to do that partialy. DF has 9mln records.
It's not duplicated coz None is not NaN value, just string. I can't replace str'None' to NaN too.