I would like to standardize my dataframe making it start and end at a precise date but i can't find the solution... I am dealing with a timeseries so it is crucial I have everything starting and ending on the same day.
I have tried several piece of code including code from stackvoerflow but nothing works.
Right now I just want rows that are between 01/01/2010 and 31/12/2017 this is the code I have so far:
df=pd.read_csv("AREX.csv", sep = ";")
df[~df['Date'].isin(pd.date_range(start='20100101', end='20171231'))]
print(df)
df.drop(["Open","High","Low","Volume","Open interest"],axis = 1, inplace=True)
print(df)
But it does not affect the number of rows it only drops the column I ask it to.
Does anyone has any idea on how to fix this?
Thank you in advance for any piece of advice you can give me!
df = df[~df['Date'].isin(pd.date_range(start='20100101', end='20171231'))]Datean actual datetime dtype column ? Second, you definitely have to assign back, otherwise your code is doing nothing. Third, instead of usingpd.date_range, use(df.Date <= '2017-12-31)& (df.Date >= '2010-01-01)`df["Date"] = pd.to_datetime(df['Date']) df = df[~df['Date'].isin(df.Date <= '2017-12-31') & (df.Date >= '2010-01-01')]Thank you @RafaelC