Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 19.4k
Closed
Labels
BugNumeric OperationsArithmetic, Comparison, and Logical operationsArithmetic, Comparison, and Logical operationsexpressionspd.eval, query, pd.colpd.eval, query, pd.col
Milestone
Description
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
importpandasaspdimportiodata='''datetime,cfs2018-02-28,3502018-03-15,4202019-04-10,3802019-06-01,450'''dd=pd.read_csv(io.StringIO(data), parse_dates=['datetime']).set_index('datetime') (dd .reset_index() .sort_values('datetime') .loc[(pd.col('datetime') >'2018-03-01') & (pd.col('datetime') <='2019-05-31')] .assign(cfs=pd.col('cfs').clip(upper=400)) )Issue Description
When using pd.col inside .loc to filter rows based on multiple conditions, combining conditions with & does not work as expected.
Expected Behavior
It works like this lambda version:
importpandasaspdimportiodata='''datetime,cfs2018-02-28,3502018-03-15,4202019-04-10,3802019-06-01,450'''dd=pd.read_csv(io.StringIO(data), parse_dates=['datetime']).set_index('datetime') (dd .reset_index() .sort_values('datetime') #.loc[(pd.col('datetime') > '2018-03-01') & (pd.col('datetime') <= '2019-05-31')] .loc[lambdadf_: (df_['datetime'] >'2018-03-01') & (df_['datetime'] <='2019-05-31')] .assign(cfs=pd.col('cfs').clip(upper=400)) )Installed Versions
Replace this line with the output of pd.show_versions()
Metadata
Metadata
Assignees
Labels
BugNumeric OperationsArithmetic, Comparison, and Logical operationsArithmetic, Comparison, and Logical operationsexpressionspd.eval, query, pd.colpd.eval, query, pd.col