Skip to content
Advertisement

How to Eliminate FOR Loop with the extraction of each value from

Unable to Extract correct values from Pandas Series to use in np.select Function as default value. # With For Loop: Getting Perfect values in column “C” [“No”,”No”,4,4,4,4,4,4]

JavaScript

”’

JavaScript

”’

JavaScript

Perfect Output with For Loop in Column "C"

Imperfect Values in Column C with np.select function instead of for loop

Advertisement

Answer

You code is equivalent to:

JavaScript

output:

JavaScript

NB. If you want to keep the object type, use: df['C'] = df['B'].where(m1&m2).ffill().convert_dtypes().astype(object).fillna(df['C'])

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