Skip to content
Advertisement

If there is a second column present then populate second column values, else populate first column values in Dataframe

I have a dataframe as seen below:

JavaScript

I need two columns now, column A and Column B. Conditions summarized:

JavaScript

The required dataframe should be as follows:

JavaScript

Advertisement

Answer

Try:

JavaScript

The !='' will work if you truly have nothing in the cell (as opposed to a NaN etc.). If you have actual NaN values use:

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