Reputation: 383
So I have the current file in Excel where I have dates and don't have dates for everything which can be seen.
I read this excel file into a pandas dataframe, rename the column and get the following:
My question is, how would I get it so every empty date in the dataframe is filled in with the last previous date encountered. All of the blanks between 04/03/2021 and 05/03/2021 gets replaced with 04/03/2021, so every row in my dataframe has a date associated with it?
Thanks!
Upvotes: 0
Views: 434
Reputation: 137
After reading the data into a dataframe, you can fill missing values using fillna with method='ffill' for forward fill
Upvotes: 1
Reputation: 383
Just using the inbuilt way in pandas of:
duplicate_df['StartDate'] = duplicate_df['StartDate'].fillna(method = 'ffill')
This replaces all the NaNs in the dataframe with the last row that had data in.
Upvotes: 0