3

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

2
  • What happens if the DF has 3 nan's? Commented Jul 23, 2019 at 23:51
  • if there are 3 nan's then there would be 3 elements in the list Commented Jul 23, 2019 at 23:52

1 Answer 1

3
df.loc[df["A"].isnull(), "A"] = values_to_be_filled
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.