Click here to Skip to main content
15,887,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
H there,

I would like to Backfill, NaN Values For a given Column, i.e. in this case 'Date', and for a Particular Date from that Column.

I have allready Forward Filled for missing Dates, in my DataFrame in Pandas. I am working with an Excel .xls File , in my DataFrame in Pandas, using Jupyter Notebook.

This is the Line Of Code I used :-

Python
df["Date"].fillna(method='ffill', inplace = True)


But I would like to narrow that down to a particular Date, this time back filling.

Could someone tell me, what I should type to do that ?

Any help would be appreciated

Regards

Eddie Winch

What I have tried:

This is the Date Sorting part of my Code :-

<pre>#return df['Durn'] column datetime64 format to object type
df['Durn'] = pd.to_datetime(df['Durn'], format='%H:%M:%S').dt.time
#print("reverted datatype of column Durn back to ----->",df['Durn'].dtype)
#print("=======")
  
#print("\n\n*** FINAL RESULTSET ***\n\n")
  
df['Date']= pd.to_datetime(df['Date'],format='%Y-%m-%d')
#df['Date']= pd.to_datetime(df['Date']).dt.strftime('%d-%m-%Y')
##added two lines above to convert date format    

df['Date'] = df['Date'].mask(df['Date'].dt.year == 2008, 
                             df['Date'] + pd.offsets.DateOffset(year=2009)) 

df=df.loc[df.Date.dt.strftime('%m%d').astype(int).argsort()]    

df['Date']= pd.to_datetime(df['Date']).dt.strftime('%d-%m-%Y')
    
pd.DataFrame(df)
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900