I have a simple problem : I have a Dataframe containing some data, read from a csv file. I need to create a new DataFrame with the entries of the first dataframe where the field 'date' is contained between the two parameters startDate and endDate.
This works when i only put one parameter (<= endDate or >= startDate for example) BUT : using | to use both conditions returns : "TypeError: unsupported operand type(s) for |: 'bool' and 'str'" and using "and" does not work since I am working with a DataFrame. Any help is appreciated.
import pandas as pd
from pandas import to_datetime
import datetime
def data_cleaning_part(startDate, endDate):
path = "./sessions.csv"
df = pd.read_csv(path)
filteredsessions = df[(pd.to_datetime(df["date"]) <= endDate) | (df[pd.to_datetime(df["date"]) >=startDate])]
filteredsessions.to_csv("filteredsessions.csv")
return filteredsessions