How do I fill repeating null values with a preceding non-null value?
df = pd.DataFrame(['a','a', None, 'b', None, None])
For instance, the data frame above would be populated as:
['a','a','a','b','b','b']
Use df.fillna with the ffill method, as follows:
df.fillna(method='ffill')
Example:
>>> df = pd.DataFrame(['a','a', None, 'b', None, None])
>>> df.fillna(method='ffill')
0
0 a
1 a
2 a
3 b
4 b
5 b
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With