I am trying to replace missing values in a column with predicted values that I saved in a list.
This is an example of what I would like to accomplish:
A B C
0 7.2 'b' 'woo'
1 nan 'v' 'sal'
2 nan 'o' 'sdd'
3 8.1 'k' 'trili'
My list will look something like this:
list = [3.2, 1.1]
And my desired result:
A B C
0 7.2 'b' 'woo'
1 3.2 'v' 'sal'
2 1.1 'o' 'sdd'
3 8.1 'k' 'trili'
I tried different approaches to this problem, but this code illustrates my general idea:
q = 0
for item in df['Age']:
if str(item) == 'nan':
item = my_list[q]
q = q + 1
Thanks in advance. It made me dunk for a while.
source
share