Pandas HR database: Create a boolean series, where True for not null and False for null values or missing values in specified column of locations file

Pandas HR database Queries: Exercise-12 with Solution

Write a Pandas program to create and display a boolean series, where True for not null and False for null values or missing values in state_province column of locations file.

Sample Solution :

Python Code :

import pandas as pd
pd.set_option('display.max_rows', 500)
pd.set_option('display.max_columns', 500)
employees = pd.read_csv(r"EMPLOYEES.csv")
departments = pd.read_csv(r"DEPARTMENTS.csv")
job_history = pd.read_csv(r"JOB_HISTORY.csv")
jobs = pd.read_csv(r"JOBS.csv")
countries = pd.read_csv(r"COUNTRIES.csv")
regions = pd.read_csv(r"REGIONS.csv")
locations = pd.read_csv(r"LOCATIONS.csv")
print("Original data / State Province")
print("\n\n   State Province(Not null / Null Series")

Sample Output:

Original data / State Province		State Province(Not null / Null Series
0                   NaN					False
1                   NaN					False
2      Tokyo Prefecture					True
3                   NaN					False
4                 Texas					True
5            California					True
6            New Jersey					True
7            Washington					True
8               Ontario					True
9                 Yukon					True
10                  NaN					False
11          Maharashtra					True
12      New South Wales					True
13                  NaN					False
14                  NaN					False
15               Oxford					True
16           Manchester					True
17              Bavaria					True
18            Sao Paulo					True
19               Geneve					True
20                   BE					True
21              Utrecht					True
22    Distrito Federal,					True
Name: state_province, dtype: object    Name: state_province, dtype: bool

Click to view the table contain:

Employees Table

Departments Table

Countries Table

Job_History Table

Jobs Table

Locations Table

Regions Table

Python Code Editor:

Structure of HR database :

HR database

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Pandas program to display the first name, last name, salary and manger id where manager ids are not null.
Next: Write a Pandas program to create a boolean series selecting rows with one or more nulls from locations file.

What is the difficulty level of this exercise?

Python: Tips of the Day

Checks if the given number falls within the given range.


def tips_range(n, start, end = 0):
  return start <= n <= end if end >= start else end <= n <= start
print(tips_range(2, 4, 6))
print(tips_range(4, 8))
print(tips_range(1, 3, 5))
print(tips_range(1, 3))