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

Popular posts from this blog

I get wrong characters when retreiving the message body of an email using TIdIMAP4.UIDRetrieveTextPeek2()

How to drop the all the 1's in a correlation matrix

Today Walkin 14th-Sept