CBSE Class 12 Informatics Practices Question 40 of 44

Data Handling using Pandas — Question 41

Back to all questions
41
Question

Question 38

Create a dataframe of {‘A’ : [5, 6], ‘B’: [3, 0], 'C': [0, 0]} and display the result of all() and any() functions.

Solution
import pandas as pd
df = pd.DataFrame({'A': [5, 6], 'B': [3, 0], 'C': [0, 0]})
print(df)

print("\nResult of all() function:")
print(df.all())

print("\nResult of any() function:")
print(df.any())
Output
   A  B  C
0  5  3  0
1  6  0  0

Result of all() function:
A     True
B    False
C    False
dtype: bool

Result of any() function:
A     True
B     True
C    False
dtype: bool
Answer

import
pandas
as
pd
df
=
pd
.
DataFrame
({
'A'
: [
5
,
6
],
'B'
: [
3
,
0
],
'C'
: [
0
,
0
]})
print
(
df
)
print
(
"
\n
Result of all() function:"
)
print
(
df
.
all
())
print
(
"
\n
Result of any() function:"
)
print
(
df
.
any
())
Output
A B C
0 5 3 0
1 6 0 0

Result of all() function:
A True
B False
C False
dtype: bool

Result of any() function:
A True
B True
C False
dtype: bool