Skip to content
Advertisement

How to cycle the NaNs in pandas dataframe rows?

I have a dataframe like this:

JavaScript

How to put all the NAs in the left instead of right?

Required:

JavaScript

Advertisement

Answer

There are mixed numeric with strings rows, so solution is use sorted with key parameter in DataFrame.apply:

JavaScript

If all values are numeric, faster solution is with justify:

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