Skip to content
Advertisement

Python pandas conditional ffill. Fill the month beginning value till that month’s end

The code below produces sample dataframe

JavaScript

The value on 1st of December is as follows

JavaScript

Which outputs 9 My question is how to use “ffill” method to have this value 9 for all days of December? I want the month beginning value to be filled till end of that month

Advertisement

Answer

Replace values for all days except the first day of the month with NaNs and use .ffill()

JavaScript
Advertisement