Pandas version checks
-
[X] I have checked that this issue has not already been reported.
-
[x] I have confirmed this bug exists on the latest version of pandas.
-
[X] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Here is an example:
import pandas as pd
df = pd.DataFrame({
'A': [5, 15, 10, 8],
'B': [20, 3, 7, 12]
})
result = (df >= 10) | (df['A'] >= 10)
result
The output:
A B 0 1 2 3
0 False True False False False False
1 True False False False False False
2 True False False False False False
3 False True False False False False
Issue Description
- I would expect the results in column
1
and column2
to beTrue
since it's an|
operation between dataframe and series. - Could you please direct me to the appropriate user manual? I couldn't locate the one that explains the logical operations between a pandas DataFrame and a Series.
Thanks a lot!
Expected Behavior
I would expect the results in column 1
and column 2
to be True
since it's an |
operation between dataframe and series.
Installed Versions
Comment From: ojmel
What do you hope to use the corrected table for?
Comment From: jialuoo
Thanks for the quick response.
I just want to clarify whether this behavior is expected or if it might be a bug. What are the rules for logical operations between a Pandas DataFrame and a Series (e.g., dataframe | dataframe, dataframe | series, etc.)? Is there any user manual or documentation that explains the rules for logical operations between a Pandas DataFrame and a Series?
At the moment, I don't have a specific goal in mind. I noticed this behavior while experimenting with the DataFrame.where method, which seems to allow these logical operations as conditions. For example: df.where((df >= 10) | (df['A'] >= 10)). So, the results of the logical operation will directly affect the dataframe.where results.
Comment From: Lavishgangwani
take
Comment From: rhshadrach
The current behavior is consistent with:
df = pd.DataFrame({"a": np.nan, "b": [True, False]})
print(df["a"] | df["b"])
# 0 False
# 1 False
# dtype: bool
although I'm not certain how intentional this behavior is. The corresponding operation with NumPy raises. Further investigations are welcome!
Comment From: Lavishgangwani
take
Comment From: Lavishgangwani
I'd like to work on this issue. Please assign it to me take.
Comment From: AshleySonny
Is anyone working on this issue?