Skip to content
Advertisement

Begginer/ numpy where and copy

I am trying to copy values from one Field2 into Field1 if Field1 is null or NaN. I have tried below where statement as per documentation, but it cuts outliners instead of copyting the value.

dataframe=np.where(dataframe['field1'].isnull(),np.copy(dataframe['field2']),1)

I have interpreted it as if statement, but apparently its wrong interpretation, as results are not correct. Has anyone of you had similar issues?

np.where source np.copy source

Advertisement

Answer

Use fillna or combine_first:

JavaScript

Demo:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement