logo_learn_stats

Find out how to Take a look at if Mobile is Uninhabited in Pandas DataFrame

Posted on
banner 336x280

You’ll worth refer to modest syntax to test if a selected cellular is deserted in a pandas DataFrame:

#take a look at if price in first row of column 'A' is deserted
print(pd.isnull(df.loc[0, 'A']))

#print price in first row of column 'A'
print(df.loc[0, 'A'])

Refer to instance displays worth this syntax in apply.

banner 468x60

Instance: Take a look at if Mobile is Uninhabited in Pandas DataFrame

Think we’ve got refer to pandas DataFrame:

import pandas as pd
import numpy as np

#assemble DataFrame
df = pd.DataFrame({'crew': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'],
                   'issues': [18, np.nan, 19, 14, 14, 11, 20, 28],
                   'assists': [5, 7, 7, 9, np.nan, 9, 9, 4],
                   'rebounds': [11, 8, 10, 6, 6, 5, 9, np.nan]})

#view DataFrame
df

	crew	issues	assists	rebounds
0	A	18.0	5.0	11.0
1	B	NaN	7.0	8.0
2	C	19.0	7.0	10.0
3	D	14.0	9.0	6.0
4	E	14.0	NaN	6.0
5	F	11.0	9.0	5.0
6	G	20.0	9.0	9.0
7	H	28.0	4.0	NaN

We will worth refer to code to test if the worth in row index quantity one and column issues is zero:

#take a look at if price in index row 1 of column 'issues' is deserted
print(pd.isnull(df.loc[1, 'points']))

True

A worth of True signifies that the worth in row index quantity probably the most “points” column is certainly deserted.

We will additionally worth refer to code to print the untouched price in row index quantity probably the most “points” column:

#print price in index row 1 of column 'issues'
print(df.loc[1, 'points'])

nan

The output tells us that the worth in row index quantity probably the most “points” column is nan, which is similar to an deserted cellular.

Spare Assets

Refer to tutorials provide an explanation for carry out alternative familiar operations in pandas:

Find out how to All set Worth for a Explicit Mobile in Pandas
Find out how to Get Mobile Worth in Pandas
Find out how to Change NaN Values with 0 in Pandas

banner 336x280

Leave a Reply

Your email address will not be published. Required fields are marked *