Method Chaining - Problem
Given a DataFrame animals with columns name, species, age, and weight, write a solution to list the names of animals that weigh strictly more than 100 kilograms.
Return the animals sorted by weight in descending order.
Input & Output
Example 1 — Basic Filtering
$
Input:
animals = [{"name":"Lion","species":"Panthera leo","age":5,"weight":80},{"name":"Elephant","species":"Loxodonta africana","age":10,"weight":150}]
›
Output:
["Elephant"]
💡 Note:
Only Elephant weighs more than 100kg (150 > 100), so return ["Elephant"]
Example 2 — Multiple Heavy Animals
$
Input:
animals = [{"name":"Rhino","species":"Rhinoceros","age":8,"weight":120},{"name":"Hippo","species":"Hippopotamus","age":6,"weight":180},{"name":"Elephant","species":"Elephantidae","age":12,"weight":150}]
›
Output:
["Hippo","Elephant","Rhino"]
💡 Note:
All three animals weigh > 100kg. Sorted by weight descending: Hippo(180), Elephant(150), Rhino(120)
Example 3 — No Heavy Animals
$
Input:
animals = [{"name":"Tiger","species":"Panthera tigris","age":4,"weight":90},{"name":"Lion","species":"Panthera leo","age":3,"weight":85}]
›
Output:
[]
💡 Note:
No animals weigh more than 100kg (Tiger: 90kg, Lion: 85kg), so return empty array
Constraints
- 1 ≤ animals.length ≤ 104
- 1 ≤ weight ≤ 1000
- name contains only letters and spaces
Visualization
Tap to expand
Understanding the Visualization
1
Input
DataFrame with animal records
2
Filter
Select animals with weight > 100kg
3
Sort & Extract
Sort by weight descending, return names
Key Takeaway
🎯 Key Insight: Use DataFrame method chaining to filter, sort, and select in one expression
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code