- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Write a Pyton program to perform Boolean logical AND, OR, Ex-OR operations for a given series
Assume you have a series and the result for Boolean operations,
And operation is: 0 True 1 True 2 False dtype: bool Or operation is: 0 True 1 True 2 True dtype: bool Xor operation is: 0 False 1 False 2 True dtype: bool
Solution
To solve this, we will follow the below approach.
Define a Series
Create a series with boolean and nan values
Perform boolean True against bitwise & operation to each element in the series defined below,
series_and = pd.Series([True, np.nan, False], dtype="bool") & True
Perform boolean True against bitwise | operation to each element in the series defined below,
series_or = pd.Series([True, np.nan, False], dtype="bool") | True
Perform boolean True against bitwise ^ operation to each element in the series defined below,
series_xor = pd.Series([True, np.nan, False], dtype="bool") ^ True
Example
Let us see the complete implementation to get a better understanding −
import pandas as pd import numpy as np series_and = pd.Series([True, np.nan, False], dtype="bool") & True print("And operation is: \n",series_and) series_or = pd.Series([True, np.nan, False], dtype="bool") | True print("Or operation is: \n", series_or) series_xor = pd.Series([True, np.nan, False], dtype="bool") ^ True print("Xor operation is: \n", series_xor)
Output
And operation is: 0 True 1 True 2 False dtype: bool Or operation is: 0 True 1 True 2 True dtype: bool Xor operation is: 0 False 1 False 2 True dtype: bool
- Related Articles
- Write a C program to perform 3X3 matrix operations
- Write a program in Python to verify kth index element is either alphabet or number in a given series
- Write a program in Python to check if a series contains duplicate elements or not
- C++ Program to Perform Operations in a BST
- Logical AND and OR in Arduino
- Write a Golang program to check whether a given number is a palindrome or not
- Write a program in Python to find the index for NaN value in a given series
- Write a Golang program to check whether a given number is prime number or not
- C program to find out the maximum value of AND, OR, and XOR operations that are less than a given value
- How to compute elementwise logical AND, OR and NOT of given input tensors in PyTorch?
- PHP program to check if a given number is present in an infinite series or not
- Write a program in Python to filter valid dates in a given series
- Write a Python program to shuffle all the elements in a given series
- Write a program in Python to filter armstrong numbers in a given series
- C program to find Fibonacci series for a given number

Advertisements