Skip to content
Advertisement

How to select rightmost column with a value?

I have a DataFrame df with some country statistics for years from 2014 to 2018. Some of the countries have values for each of the years, while some countries are missing some. The DataFrame looks like this:

JavaScript

I want to keep only the most recent data value, so for the DataFrame above, the result should be:

JavaScript

Advertisement

Answer

You could use the forward fill on the columns axis to get the last numeric values

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