Is it correct to fill a pandas dataframe with NaN values? In specific: if I have a dataframe with a user name and his age is it ok to fill the age column with int and NaN values.

Names  Age 
Lisa   25
Jack   NaN
Tom    32

Later on I want to work with this dataframe, will I get any problems if I have NaN values in it?

  • $\begingroup$ What are you going to do with thos NaN values? $\endgroup$
    – Leevo
    Jan 13, 2021 at 14:00
  • $\begingroup$ so later on I will to use the pivot_table function. I am not sure how to fill cell with values if they don't have values. in this case if I wouldn't know how old jack is $\endgroup$
    – Loretta
    Jan 13, 2021 at 14:06
  • $\begingroup$ Imputation of missing data is a very common step in data pre-processing. I suggest you to read something about it to find the best technique for your task. $\endgroup$
    – Leevo
    Jan 13, 2021 at 14:09

1 Answer 1


It depends on what problems you are afraid of:

  • regarding "technical" issues, it should be ok having NaNs in your dataframe and, afterwards, applying the pd.isna(column_name) per attribute to get a boolean mask to find those unknown values per column, more info here
  • in case your problem is not knowing the actual values, one option is imputation, but not all types of variables are easily imputable (neither it makes sense to impute all of them)

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.