Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Data Structures for HR Data | Introduction to People Analytics with Python
Python for People Analytics

bookData Structures for HR Data

メニューを表示するにはスワイプしてください

Understanding how to store and manipulate employee information is a foundational skill in people analytics. In Python, you will commonly use lists, dictionaries, and DataFrames to organize HR data. Each of these data structures offers unique advantages for managing employee records.

A list allows you to keep an ordered collection of items, such as employee records. A dictionary lets you store data as key-value pairs, making it easy to represent attributes like name, department, and salary for each employee. When you combine these, you can create a list of dictionaries, where each dictionary represents an individual employee.

For more advanced analysis, the pandas DataFrame provides a tabular structure similar to a spreadsheet, which is ideal for handling large HR datasets. DataFrames make it easy to filter, aggregate, and visualize employee data.

1234567891011
# Creating a list of dictionaries, each representing an employee employees = [ {"id": 1, "name": "Alice", "department": "HR", "salary": 60000}, {"id": 2, "name": "Bob", "department": "IT", "salary": 75000}, {"id": 3, "name": "Charlie", "department": "Finance", "salary": 70000}, {"id": 4, "name": "Diana", "department": "IT", "salary": 80000} ] # Display the list of employees for employee in employees: print(employee)
copy

You can access and update employee records using Python's list and dictionary methods. To retrieve the department of the second employee, you use employees[1]["department"]. If you want to update Bob's salary, you can assign a new value with employees[1]["salary"] = 77000.

Lists allow you to add or remove employee records using methods like append() or remove(). Dictionaries let you access or change specific attributes by key. This flexible approach makes it easy to manage HR data as employee information changes over time.

123456
# Filtering employees by department using a list comprehension it_employees = [emp for emp in employees if emp["department"] == "IT"] # Display IT department employees for emp in it_employees: print(emp["name"], "-", emp["department"])
copy

1. Which data structure allows you to store multiple employee records with named attributes?

2. Fill in the blank: To filter employees in a specific department, you can use a ____ comprehension.

3. What is the advantage of using a DataFrame over a list of dictionaries for HR data?

question mark

Which data structure allows you to store multiple employee records with named attributes?

正しい答えを選んでください

question-icon

Fill in the blank: To filter employees in a specific department, you can use a ____ comprehension.

question mark

What is the advantage of using a DataFrame over a list of dictionaries for HR data?

正しい答えを選んでください

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 1.  3

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 1.  3
some-alt