Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Challenge: Plot Department Distribution | Analyzing Employee Data
Python for HR Specialists

bookChallenge: Plot Department Distribution

Recalling what you have learned about working with lists and dictionaries, you know that counting items in a list can be efficiently achieved using a dictionary, where each unique item serves as a key and its value is the count of occurrences. This is particularly useful in HR scenarios, such as determining how many employees belong to each department. You have also previously explored the basics of using matplotlib to create bar charts, which is a powerful way to visualize categorical data like department distributions.

123456789101112
departments = ["HR", "IT", "Finance", "IT", "HR", "Marketing", "Finance", "IT"] # Count occurrences using a dictionary department_counts = {} for dept in departments: if dept in department_counts: department_counts[dept] += 1 else: department_counts[dept] = 1 print(department_counts) # Output: {'HR': 2, 'IT': 3, 'Finance': 2, 'Marketing': 1}
copy

Once you have the counts for each department stored in a dictionary, you can pass the department names and their corresponding counts to matplotlib's bar chart function. The keys of the dictionary will serve as the labels for each bar, and the values will determine the height of each bar, making it easy to visualize the employee distribution across departments.

Aufgabe

Swipe to start coding

Write a function that takes a list of department names and visualizes the number of employees in each department as a bar chart.

  • Count the number of occurrences for each unique department in the list.
  • Use the department names as labels on the x-axis and their counts as the heights of the bars.
  • Display the bar chart with appropriate axis labels and a title.

Lösung

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 2. Kapitel 3
single

single

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

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

Suggested prompts:

How do I create a bar chart using this department count data?

Can you explain how to extract the keys and values from the dictionary for plotting?

What other types of visualizations can I use for this data?

close

bookChallenge: Plot Department Distribution

Swipe um das Menü anzuzeigen

Recalling what you have learned about working with lists and dictionaries, you know that counting items in a list can be efficiently achieved using a dictionary, where each unique item serves as a key and its value is the count of occurrences. This is particularly useful in HR scenarios, such as determining how many employees belong to each department. You have also previously explored the basics of using matplotlib to create bar charts, which is a powerful way to visualize categorical data like department distributions.

123456789101112
departments = ["HR", "IT", "Finance", "IT", "HR", "Marketing", "Finance", "IT"] # Count occurrences using a dictionary department_counts = {} for dept in departments: if dept in department_counts: department_counts[dept] += 1 else: department_counts[dept] = 1 print(department_counts) # Output: {'HR': 2, 'IT': 3, 'Finance': 2, 'Marketing': 1}
copy

Once you have the counts for each department stored in a dictionary, you can pass the department names and their corresponding counts to matplotlib's bar chart function. The keys of the dictionary will serve as the labels for each bar, and the values will determine the height of each bar, making it easy to visualize the employee distribution across departments.

Aufgabe

Swipe to start coding

Write a function that takes a list of department names and visualizes the number of employees in each department as a bar chart.

  • Count the number of occurrences for each unique department in the list.
  • Use the department names as labels on the x-axis and their counts as the heights of the bars.
  • Display the bar chart with appropriate axis labels and a title.

Lösung

Switch to desktopWechseln Sie zum Desktop, um in der realen Welt zu übenFahren Sie dort fort, wo Sie sind, indem Sie eine der folgenden Optionen verwenden
War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 2. Kapitel 3
single

single

some-alt