0

I have an example data frame let's call it df. I want to add more numbers to df but i don't want to start adding after NaN's which will be the index 7 i want to start adding from index 3.

    year        number      letter
0   1945        10          a
1   1950        15          b
2   1955        20          c
3   1960        NaN         NaN
4   1965        NaN         Nan
5   1970        NaN         Nan
6   1975        NaN         Nan

Let's say we have a column like this:

    number2
0   25
1   30
2   35
3   40

my target is to get a df like this

 year        number      letter
 0  1945        10          a
 1  1950        15          b
 2  1955        20          c
 3  1960        25         NaN
 4  1965        30         Nan
 5  1970        35         Nan
 6  1975        40         Nan

I hope I explained it well enough. Thank you for your support !

luthierz
  • 51
  • 7
  • Hi, I see you're new to SO. If you feel an answer solved the problem, please mark it as 'accepted' by clicking the green check mark. This helps keep the focus on older SO which still don't have answers. – Niv Dudovitch Sep 06 '21 at 11:46

1 Answers1

2
number2 = [25,30,35,40]
df.loc[df.number.isna(), 'number'] = number2

Result df:

enter image description here

Niv Dudovitch
  • 1,614
  • 7
  • 15