Question: 33
(Choose 1 answer)
Given the following DataFrame df:
import pandas as pd
data = {
'Department': ['HR', 'HR', 'IT', 'IT', 'Sales', 'Sales', 'HR', 'IT'],
'Employee': [Hieu', 'Hao', 'Hoa', 'Kiem', 'Khanh', 'Phuc', 'Thư', 'Nga'],
'Salary': [50000, 60000, 70000, 80000, 75000, 90000, 65000, 72000]
df = pd.DataFrame(data)
Which of the following code snippets will correctly calculate the average salary by department?
A. df.groupby('Department')['Salary'].mean()
B. df.groupby('Department')['Salary'].average()
C. df.groupby('Employee')['Salary'].mean()
D. df.groupby('Department')['Salary'].count()