Reputation: 85
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']
Upvotes: 3
Views: 245
Reputation: 1979
Use df.fillna with the ffill method, as follows:
ffill
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
Upvotes: 7