Reputation: 113
The example below shows the problem: no filtering for date < date1 ... thanks!
df_test = df[1:5]
print(df_test)
date1 = "04-05-1992"
print(df_test.date >= date1)
date open high low close volume
1 30/04/1992 2.02 2.32 1.95 1.98 0
2 04/05/1992 2.32 2.32 2.02 2.21 115160
3 05/05/1992 2.27 2.43 2.27 2.27 0
4 06/05/1992 2.43 2.54 2.43 2.43 0
1 True
2 True
3 True
4 True
Name: date, dtype: bool
Upvotes: 0
Views: 59
Reputation: 113
I have decided to open this new post, for better visualization. :)
df_test = df.date[1:5]
df_test2 = pd.to_datetime(df_test, dayfirst=True)
print(df_test2)
date1 = "1992-05-04"
print(df_test2 >= date1)
1 1992-04-30
2 1992-05-04
3 1992-05-05
4 1992-05-06
Name: date, dtype: datetime64[ns]
1 False
2 True
3 True
4 True
Name: date, dtype: bool
Upvotes: 0
Reputation: 699
Dates and times are essentially their own component in pandas. See the supporting documentation here: https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html
I cannot see your code, but I'd wager you haven't setup the columns to be recognized as dates and times yet. Try that first. If this does not work, let me know and if possible post more of your code.
Hope this helps!
Upvotes: 2