w3resource

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


2. Display All Location IDs from LOCATIONS File

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


For more Practice: Solve these Related Problems:

  • Write a Pandas program to extract the location_id column from LOCATIONS.csv and display its unique values.
  • Write a Pandas program to extract and convert the location_id column into a list, then display the list.
  • Write a Pandas program to extract location_id values from LOCATIONS.csv and count the frequency of each ID.
  • Write a Pandas program to filter LOCATIONS.csv by a condition on another column (e.g., region_id > 2) and then display only the location_id column.

Go to:


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.

Python Code Editor:

Structure of HR database :

HR database

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

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.