Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Data Structures for HR Data | Introduction to People Analytics with Python
Practice
Projects
Quizzes & Challenges
Quizze
Challenges
/
Python for People Analytics

bookData Structures for HR Data

Swipe um das Menü anzuzeigen

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?

Select the correct answer

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?

Select the correct answer

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 3

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

Abschnitt 1. Kapitel 3
some-alt