Filter and Sort a DataFrame
Given a DataFrame of employees (name, department, salary), filter to show only those earning above 50000, sorted by salary in descending order.
Approach: build the DataFrame from the given rows, filter with a boolean condition (df["salary"] > 50000), then sort_values("salary", ascending=False).
Input: First line: the number of employees n. Next n lines: name,department,salary.
Output: One line per employee earning above 50000, sorted by salary descending, each as a tuple (name, department, salary).
3 Aditi,CS,60000 Rohan,AI,45000 Zara,CS,72000
('Zara', 'CS', 72000)
('Aditi', 'CS', 60000)- 1 <= n <= 1000
Hint 1
df[df["salary"] > 50000] keeps only the rows where the condition is True.
Hint 2
.sort_values("salary", ascending=False) sorts the filtered result from highest to lowest salary.
Hint 3
df.itertuples(index=False) lets you loop over rows as plain tuples, ready to print directly.
df[df["salary"] > 50000] filters down to just the employees earning above 50000, and .sort_values("salary", ascending=False) orders what's left from highest to lowest. Looping over the result with itertuples(index=False) and printing each one gives exactly the required (name, department, salary) rows, in the correct order.