2 years ago
#72034

thebearjew24
Filling NA based on match from other column
Hi I am attempting to fill NAs of one column based on the unique value of another column.
Here is an example of the df I am working with:
CompanyID | CompanyName |
---|---|
34 | Company1 |
NaN | Company1 |
NaN | Company1 |
57 | Company2 |
57 | Company2 |
NaN | Company2 |
63 | Company3 |
63 | Company3 |
NaN | Company3 |
NaN | Company3 |
My desired output:
CompanyID | CompanyName |
---|---|
34 | Company1 |
34 | Company1 |
34 | Company1 |
57 | Company2 |
57 | Company2 |
57 | Company2 |
63 | Company3 |
63 | Company3 |
63 | Company3 |
63 | Company3 |
How can I fill these NAs correctly and efficiently based off of the CompanyName? Usually at least 1 row has the CompanyID provided. Thanks!
pandas
matching
fillna
0 Answers
Your Answer