w3resource

Pandas SQL Query: Display all the location id from locations file

Pandas HR database Queries: Exercise-2 with Solution

Write a Pandas program to display all the location id from locations file.

LOCATIONS.csv

Sample Solution :

Python Code :

import pandas as pd
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")
result = locations[['location_id']]
print("All the locations id from locations file:")
print(result)

Sample Output:

All the locations id from locations file:
    location_id
0          1000
1          1100
2          1200
3          1300
4          1400
5          1500
6          1600
7          1700
8          1800
9          1900
10         2000
11         2100
12         2200
13         2300
14         2400
15         2500
16         2600
17         2700
18         2800
19         2900
20         3000
21         3100
22         3200

Equivalent SQL Syntax:

SELECT location_id  FROM LOCATIONS;

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 all the records of REGIONS file.
Next: Write a Pandas program to extract first 7 records from employees file.

What is the difficulty level of this exercise?



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://198.211.115.131/python-exercises/pandas/sql/python-pandas-hr-database-queries-exercise-2.php