LeetCode 2878.获取DataFrame的大小

DataFrame players:

±------------±-------+

| Column Name | Type |

±------------±-------+

| player_id | int |

| name | object |

| age | int |

| position | object |

| ... | ... |

±------------±-------+

编写一个解决方案,计算并显示 players 的 行数和列数。

将结果返回为一个数组:

number of rows, number of columns

返回结果格式如下示例所示。

示例 1:

输入:

±----------±---------±----±------------±-------------------+

| player_id | name | age | position | team |

±----------±---------±----±------------±-------------------+

| 846 | Mason | 21 | Forward | RealMadrid |

| 749 | Riley | 30 | Winger | Barcelona |

| 155 | Bob | 28 | Striker | ManchesterUnited |

| 583 | Isabella | 32 | Goalkeeper | Liverpool |

| 388 | Zachary | 24 | Midfielder | BayernMunich |

| 883 | Ava | 23 | Defender | Chelsea |

| 355 | Violet | 18 | Striker | Juventus |

| 247 | Thomas | 27 | Striker | ParisSaint-Germain |

| 761 | Jack | 33 | Midfielder | ManchesterCity |

| 642 | Charlie | 36 | Center-back | Arsenal |

±----------±---------±----±------------±-------------------+

输出:

10, 5

解释:

这个 DataFrame 包含 10 行和 5 列。

DataFrame有一个shape属性,调用时返回一个元组(number of rows, number of columns),将其转换为列表即可:

cpp 复制代码
import pandas as pd

def getDataframeSize(players: pd.DataFrame) -> List[int]:
    return [players.shape[0], players.shape[1]]
相关推荐
CQ_YM11 分钟前
数据结构之栈
数据结构·算法·
爱学习的梵高先生25 分钟前
C++:基础知识
开发语言·c++·算法
xlq2232233 分钟前
24.map set(下)
数据结构·c++·算法
繁华似锦respect1 小时前
C++ & Linux 中 GDB 调试与内存泄漏检测详解
linux·c语言·开发语言·c++·windows·算法
立志成为大牛的小牛1 小时前
数据结构——五十四、处理冲突的方法——开放定址法(王道408)
数据结构·学习·程序人生·考研·算法
代码游侠2 小时前
复习——栈、队列、树、哈希表
linux·数据结构·学习·算法
碧海银沙音频科技研究院2 小时前
基于物奇wq7036与恒玄bes2800智能眼镜设计
arm开发·人工智能·深度学习·算法·分类
小白程序员成长日记3 小时前
2025.12.03 力扣每日一题
算法·leetcode·职场和发展
元亓亓亓3 小时前
LeetCode热题100--20. 有效的括号--简单
linux·算法·leetcode
熊猫_豆豆3 小时前
LeetCode 49.字母异位组合 C++解法
数据结构·算法·leetcode