'Replace NA values with the values of another column using Siuba in Python
I have a dataframe (df) like this:
id users_x users_y
1 2012-04-01 1 NA
2 2012-04-02 2 NA
3 2012-04-03 3 NA
4 2012-04-04 4 NA
5 2012-04-05 5 NA
6 2012-04-06 NA 6
7 2012-04-07 NA 7
8 2012-04-08 NA NA
9 2012-04-09 NA NA
I aim to fill the NA with a new variable users which combines information from both. The the ideal output should be something like this.
id users_x users_y users
1 2012-04-01 1 NA 1
2 2012-04-02 2 NA 2
3 2012-04-03 3 NA 3
4 2012-04-04 4 NA 4
5 2012-04-05 5 NA 5
6 2012-04-06 NA 6 6
7 2012-04-07 NA 7 7
8 2012-04-08 NA NA NA
9 2012-04-09 NA NA NA
Using Siuba from Python on this fashion df >> mutate(users = if_else(isna(_.users_x), _.users_y, _.users_x)). Yet I am having problems to identify the NA using isna() method (NameError: name 'isna' is not defined). Is there a way to overcome this problem? Thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
