Skip to content
Advertisement

Shift column position to right based on criteria using Pandas

I have a dataframe that looks like below

JavaScript

I would like to position shift by 1 cell to the right if there is NA in the column dep_id.

I tried the below but it wasn’t working

JavaScript

Any efficient and elegant approach to shift column position on big data?

For example, I expect my output to be like as shown below

enter image description here

Advertisement

Answer

Let us try shift along axis=1

JavaScript

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