mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-06 07:51:41 +08:00
update
This commit is contained in:
52
leetcode/problem/method-chaining.html
Normal file
52
leetcode/problem/method-chaining.html
Normal file
@@ -0,0 +1,52 @@
|
||||
<pre>
|
||||
DataFrame <code>animals</code>
|
||||
+-------------+--------+
|
||||
| Column Name | Type |
|
||||
+-------------+--------+
|
||||
| name | object |
|
||||
| species | object |
|
||||
| age | int |
|
||||
| weight | int |
|
||||
+-------------+--------+
|
||||
</pre>
|
||||
|
||||
<p>Write a solution to list the names of animals that weigh <strong>strictly more than</strong> <code>100</code> kilograms.</p>
|
||||
|
||||
<p>Return the animals sorted by weight in <strong>descending order</strong>.</p>
|
||||
|
||||
<p>The result format is in the following example.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong>
|
||||
DataFrame animals:
|
||||
+----------+---------+-----+--------+
|
||||
| name | species | age | weight |
|
||||
+----------+---------+-----+--------+
|
||||
| Tatiana | Snake | 98 | 464 |
|
||||
| Khaled | Giraffe | 50 | 41 |
|
||||
| Alex | Leopard | 6 | 328 |
|
||||
| Jonathan | Monkey | 45 | 463 |
|
||||
| Stefan | Bear | 100 | 50 |
|
||||
| Tommy | Panda | 26 | 349 |
|
||||
+----------+---------+-----+--------+
|
||||
<strong>Output:</strong>
|
||||
+----------+
|
||||
| name |
|
||||
+----------+
|
||||
| Tatiana |
|
||||
| Jonathan |
|
||||
| Tommy |
|
||||
| Alex |
|
||||
+----------+
|
||||
<strong>Explanation:</strong>
|
||||
All animals weighing more than 100 should be included in the results table.
|
||||
Tatiana's weight is 464, Jonathan's weight is 463, Tommy's weight is 349, and Alex's weight is 328.
|
||||
The results should be sorted in descending order of weight.</pre>
|
||||
|
||||
<p> </p>
|
||||
<p>In Pandas, <strong>method chaining</strong> enables us to perform operations on a DataFrame without breaking up each operation into a separate line or creating multiple temporary variables. </p>
|
||||
|
||||
<p>Can you complete this task in just <strong>one line </strong>of code using method chaining?</p>
|
Reference in New Issue
Block a user