Replace empty values with values of other records in a dataframe
I have the following problem
I need to replace the empty cel values in dataframe with the values of the costs of CustomerNr of other records
df1 = pd.DataFrame([[1004,''], [1004, 'D'],[1005, 'C'],
[1010,'A'], [1010,''],[1010,''],[1010,''],[1004, '']], columns=['CustomerNr','Costs'])
CustomerNr | Costs |
---|---|
1004 | |
1004 | D |
1005 | C |
1010 | A |
1010 | |
1010 | |
1010 | |
1004 |
Desired output:
CustomerNr | Costs |
---|---|
1004 | D |
1004 | D |
1005 | C |
1010 | A |
1010 | A |
1010 | A |
1010 | A |
1004 | D |
Comments
Post a Comment