0

I read in a file with pandas which looks like:

import pandas as pd
import numpy as np

data = {'first_set_of_numbers':  [1,2,3,4,5,np.nan,6,7,np.nan,np.nan,8,9,10,np.nan],
        'second_set_of_numbers': [11,12,np.nan,13,14,np.nan,15,16,np.nan,np.nan,17,np.nan,19,np.nan],
        'third_set_of_numbers': [20,21,22,23,np.nan,24,np.nan,26,27,np.nan,np.nan,28,29,30]
       }

My goal is to go through column three and check if a cell is "nan" and if yes then print the whole row and then the user shall be asked to insert some kind of text.

So something like:

This is not working:

for x in data['third_set_of_numbers']:
    if pd.isna(x):
       print(data[x])
       userinput = input("Enter Name:")
       data['third_set_of_numbers'][x] = userinput

Any idea?

Thank you for your help!

Kevin
  • 1
  • 1
  • df['third_set_of_numbers'].fillna('Jon', inplace=True) – Tornike Kharitonishvili Feb 22 '23 at 07:57
  • I would say the dupe link is wrong (this is not a `df.fillna` question), but the question is still a bit odd. You tagged it as `pandas` and `dataframe`, but there's no pandas dataframe here. `data` just a plain dict. This code should do what you want: https://i.stack.imgur.com/Lhukw.png – tdy Feb 26 '23 at 20:34
  • On the first line, enumerate the data to get both the index `i` and value `x`. On the print line, `print(data[x])` should just be `print(x)`. On the last line, `data['third_set_of_numbers'][x]` should be `data['third_set_of_numbers'][i]`. – tdy Feb 26 '23 at 20:39

0 Answers0