Pandas any() and all() function | pandas any vs all

Опубликовано: 09 Октябрь 2024
на канале: technologyCult
2,024
24

Pandas any() and all() function | pandas any vs all

Pandas any() function
Pandas any() function is used to check whether any element is True over the axis.
It returns False unless there are at least one element with the series that is True.

Pandas all() function
Pandas all() function is used to check whether all elements are True, potentially over an axis.
It returns True unless there are at least one element with the series that is False.

Code Starts Here
===============
import pandas as pd
import numpy as np

pd.Series([False,False]).any()
pd.Series([False,False]).all()

pd.Series([True,False]).any()
pd.Series([True,False]).all()

pd.Series([True,True]).any()
pd.Series([True,True]).all()

X = pd.Series([4,5,1,5,1,9,7])

X.any()
X.all()

any(X)
all(X)

any( X GT 1)
all( X GT 1)

df = pd.DataFrame()

df['x'] = [1,2,39,4,5]
df['y'] = [6,7,8,9,10]

if all(df['x'] LT df['y']):
print('True')
else:
print('False')

df['x'] = [1,2,3,4,5]
df['y'] = [6,7,8,9,10]

if any(df['x'] GT df['y']):
print('True')
else:
print('False')

df = pd.read_csv('train.csv')

a. IF any person is there with age 70, 75, 80
(df.Age == 70).any()
df[df.Age == 70]

(df.Age == 75).any()

(df.Age == 80).any()
df[df.Age == 80]

b. check if any person is travelling without any Fare
(df.Fare == 0).any()
df[df.Fare == 0]
(df.Fare == 0).all()

c. Check if any infant is travelling
(df.Age LT 1).any()
df[df.Age LT 1]

All Playlist of this youtube channel
=============================

1. Data Preprocessing in Machine Learning
   • Data Preprocessing in Machine Learnin...  

2. Confusion Matrix in Machine Learning, ML, AI
   • Confusion Matrix in Machine Learning,...  

3. Anaconda, Python Installation, Spyder, Jupyter Notebook, PyCharm, Graphviz
   • Anaconda | Python Installation | Spyd...  

4. Cross Validation, Sampling, train test split in Machine Learning
   • Cross Validation | Sampling | train t...  

5. Drop and Delete Operations in Python Pandas
   • Drop and Delete Operations in Python ...  

6. Matrices and Vectors with python
   • Matrices and Vectors with python  

7. Detect Outliers in Machine Learning
   • Detect Outliers in Machine Learning  

8. TimeSeries preprocessing in Machine Learning
   • TimeSeries preprocessing in Machine L...  

9. Handling Missing Values in Machine Learning
   • Handling Missing Values in Machine Le...  

10. Dummy Encoding Encoding in Machine Learning
   • Label Encoding, One hot Encoding, Dum...  

11. Data Visualisation with Python, Seaborn, Matplotlib
   • Data Visualisation with Python, Matpl...  

12. Feature Scaling in Machine Learning
   • Feature Scaling in Machine Learning  

13. Python 3 basics for Beginner
   • Python | Python 3 Basics | Python for...  

14. Statistics with Python
   • Statistics with Python  

15. Sklearn Scikit Learn Machine Learning
   • Sklearn Scikit Learn Machine Learning  

16. Python Pandas Dataframe Operations
   • Python Pandas Dataframe Operations  

17. Linear Regression, Supervised Machine Learning
   • Linear Regression | Supervised Machin...  

18 Interview Questions on Machine Learning and Data Science
   • Interview Question for Machine Learni...  

19. Jupyter Notebook Operations
   • Jupyter and Spyder Notebook Operation...