Skip to content

Commit 8aa17e9

Browse files
committed
Add pandas code 586,595,596
1 parent 58b84cb commit 8aa17e9

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# https://leetcode.cn/problems/customer-placing-the-largest-number-of-orders
2+
3+
import pandas as pd
4+
5+
6+
def largest_orders(orders: pd.DataFrame) -> pd.DataFrame:
7+
'''
8+
Date: 2023.08.07
9+
Pass/Error/Bug: 1/0/0
10+
执行用时: 280 ms, 在所有 Python3 提交中击败了 66.40% 的用户
11+
内存消耗:60.20 Mb, 在所有 Python3 提交中击败了 41.33% 的用户
12+
'''
13+
return (
14+
orders
15+
.groupby('customer_number').count()
16+
.sort_values('order_number', ascending=False)
17+
.reset_index().head(1)[['customer_number']]
18+
)

595.big-countries.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# https://leetcode.cn/problems/big-countries
2+
3+
import pandas as pd
4+
5+
6+
def big_countries(world: pd.DataFrame) -> pd.DataFrame:
7+
'''
8+
Date: 2023.07.31
9+
Pass/Error/Bug: 1/1/0
10+
执行用时: 292 ms, 在所有 Python3 提交中击败了 21.90% 的用户
11+
内存消耗:61.30 Mb, 在所有 Python3 提交中击败了 79.58% 的用户
12+
'''
13+
return world.query('area >= 3000000 or population >= 25000000')[['name','population','area']]

596.classes-more-than-5-students.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# https://leetcode.cn/problems/classes-more-than-5-students
2+
3+
import pandas as pd
4+
5+
6+
def find_classes(courses: pd.DataFrame) -> pd.DataFrame:
7+
'''
8+
Date: 2023.08.07
9+
Pass/Error/Bug: 1/1/0
10+
执行用时: 256 ms, 在所有 Python3 提交中击败了 62.80% 的用户
11+
内存消耗:60.70 Mb, 在所有 Python3 提交中击败了 50.56% 的用户
12+
'''
13+
return courses.groupby('class').count().query('student>=5').reset_index().loc[:, ['class']]

0 commit comments

Comments
 (0)