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]]
相关推荐
冲帕Chompa14 分钟前
图论part10 bellman_ford算法
数据结构·算法·图论
緈福的街口16 分钟前
【leetcode】144. 二叉树的前序遍历
算法·leetcode
GG不是gg22 分钟前
排序算法之基础排序:冒泡,选择,插入排序详解
数据结构·算法·青少年编程·排序算法
随意起个昵称44 分钟前
【双指针】供暖器
算法
倒霉蛋小马1 小时前
最小二乘法拟合直线,用线性回归法、梯度下降法实现
算法·最小二乘法·直线
codists1 小时前
《算法导论(第4版)》阅读笔记:p82-p82
算法
埃菲尔铁塔_CV算法1 小时前
深度学习驱动下的目标检测技术:原理、算法与应用创新
深度学习·算法·目标检测
Dream it possible!2 小时前
LeetCode 热题 100_寻找重复数(100_287_中等_C++)(技巧)(暴力解法;哈希集合;二分查找)
c++·leetcode·哈希算法
float_com2 小时前
【背包dp-----分组背包】------(标准的分组背包【可以不装满的 最大价值】)
算法·动态规划
丶Darling.2 小时前
Day119 | 灵神 | 二叉树 | 二叉树的最近共公共祖先
数据结构·c++·算法·二叉树