Issue
I have this dataset, where I will use to fill missing values.
In [1]: sex_class = ['female','male']
pclass = [1,2,3]
fill_values = [34,40,29,18,24,25]
In [2]: for i in pclass:
for j in sex_class:
print(i,j)
Out[2]: 1 female
1 male
2 female
2 male
3 female
3 male
How can I make it so that the output will appear as:
1 female 34
1 male 40
2 female 29
2 male 18
3 female 24
3 male 25
Solution
You could do with pop
for the list
sex_class = ['female','male']
pclass = [1,2,3]
fill_values = [34,40,29,18,24,25]
for i in pclass:
for j in sex_class:
print(i,j,fill_values.pop(0))
1 female 34
1 male 40
2 female 29
2 male 18
3 female 24
3 male 25
Answered By - BENY
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.