Skip to content
Advertisement

Merging pandas columns into a new column

Suppose I have a dataframe as follows

JavaScript

how can I merge the two columns into one using pandas? The desired output is

output

JavaScript

Thank you!

Advertisement

Answer

Use Series.fillna with DataFrame.pop for replace missing values to another column with drop second column:

JavaScript

Or you can back filling missing values with select first column by DataFrame.iloc with [[0]] for one column DataFrame from first column:

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