I'm trying to make a temporary dataframe that is created by filtering an existing dataframe (stock_data
) based on two criteria;
- The
stock_data
ticker column is matching thetick_id
variable - The
stock_data
date column is within a range fromstart
toend
(the variables are created usingpd.to_datetime
)
I've attempted this using two different solutions
First:
temp = stock_data[(stock_data.ticker == tick_id) & (stock_data["date"].isin(pd.date_range(start, end)))]
Second:
mask = (stock_data.ticker == tick_id) & ((stock_data.date > start) & (stock_data.date <= end))
temp = stock_data.loc[mask]
Both solutions result in the same error:
ValueError: Can only compare identically-labeled Series objects