Sai Teja Akula
Sai Teja Akula

Reputation: 41

Replacing the missing values in python with Lists in python dataframe

I have a dataframe and wanted to fill the Nan values of particular column with the list derived from other calculation.

df = pd.DataFrame([1,Nan,3,Nan], columns=['A'])
values_to_be_filled = [100.942,90.942]


df
     A
0    1
1    Nan
2    3
3  Nan



output: 

df2 
      A
 0    1
 1    100.942
 2    3
 3    90.942

I have tried use the replace function but not able to replace with the list elements. Any help would be much appreciated

Upvotes: 3

Views: 394

Answers (1)

GZ0
GZ0

Reputation: 4268

df.loc[df["A"].isnull(), "A"] = values_to_be_filled

Upvotes: 3

Related Questions