EasyNo. 2891
Method Chaining — LeetCode 2891 Python Solution
- Topics
- Pandas
- Reading time
- 2 min
- Source
- leetcode.com
Table schema
DataFrame animals +-------------+--------+ | Column Name | Type | +-------------+--------+ | name | object | | species | object | | age | int | | weight | int | +-------------+--------+ 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.Example
DataFrame animals
+-------------+--------+
| Column Name | Type |
+-------------+--------+
| name | object |
| species | object |
| age | int |
| weight | int |
+-------------+--------+Python solution
import pandas as pd
def findHeavyAnimals(animals: pd.DataFrame) -> pd.DataFrame:
return animals[animals['weight'] > 100].sort_values('weight', ascending=False)[
['name']
]Complexity
- Time
- O(n)
- Space · auxiliary
- O(1) to O(n)
Related problems
| No. | Problem | Difficulty |
|---|---|---|
| 2877 | Create a DataFrame from List | Easy |
| 0057 | Insert Interval | Medium |
| 0192 | Word Frequency | Medium |
| 0193 | Valid Phone Numbers | Easy |
| 0194 | Transpose File | Medium |
| 0195 | Tenth Line | Easy |
Frequently asked questions
- How hard is LeetCode 2891. Method Chaining?
LeetCode 2891. Method Chaining is rated Easy on LeetCode.
- What topics does LeetCode 2891. Method Chaining cover?
LeetCode 2891. Method Chaining is tagged Pandas on LeetCode.