mercredi 28 décembre 2016

How to do conditional statements in pandas/python with null valves

How do I do condition replacements in pandas?

df = pd.DataFrame([[1, 2, 3], [4, None, None], [None, None, 9]])

In R - think this code is very easy to understand:

library(dplyr)
df = df %>% 
mutate(   #   mutate means create new column for non-r people
my_new_column = ifelse( is.na(the_2nd_column)==TRUE & is.na(the_3rd_column)==TRUE, ' abc', 'cuz')

how do I do this in pandas - probably dumb question with the syntax, but I have heard np.where is the equivalent of if else in R...

df['new_column'] = np.where(np.nan(....help here with a conditional....))

Aucun commentaire:

Enregistrer un commentaire