Answering simple questions about a dataset
Let's take an example to look at a few questions and answer them. Say the HR director asks you to answer a few descriptive questions about the employees of the company. The following are a few such questions:
- How many employees are there by department in the dataset?
- What is the overall attrition rate?
- What is the average hourly rate?
- What is the average number of years at the company?
- Who are the five employees with the most number of years at the company?
- How satisfied are employees overall?
Total employees by department in the dataset
To view the departments in the dataset, you use the data['Department']
statement. We get the column called Department
, which is a pandas
series, and for every employee, you have the department to which the employee belongs. So, to compute how many times you see each department in this pandas
series, you use the value_counts()
method:

In the preceding screenshot, you can see that the count for every unique value from Department...