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]]
相关推荐
焦耳加热3 小时前
阿德莱德大学Nat. Commun.:盐模板策略实现废弃塑料到单原子催化剂的高值转化,推动环境与能源催化应用
人工智能·算法·机器学习·能源·材料工程
wan5555cn4 小时前
多张图片生成视频模型技术深度解析
人工智能·笔记·深度学习·算法·音视频
u6064 小时前
常用排序算法核心知识点梳理
算法·排序
蒋星熠6 小时前
Flutter跨平台工程实践与原理透视:从渲染引擎到高质产物
开发语言·python·算法·flutter·设计模式·性能优化·硬件工程
小欣加油7 小时前
leetcode 面试题01.02判定是否互为字符重排
数据结构·c++·算法·leetcode·职场和发展
3Cloudream7 小时前
LeetCode 003. 无重复字符的最长子串 - 滑动窗口与哈希表详解
算法·leetcode·字符串·双指针·滑动窗口·哈希表·中等
王璐WL7 小时前
【c++】c++第一课:命名空间
数据结构·c++·算法
空白到白8 小时前
机器学习-聚类
人工智能·算法·机器学习·聚类
索迪迈科技8 小时前
java后端工程师进修ing(研一版 || day40)
java·开发语言·学习·算法
zzzsde8 小时前
【数据结构】队列
数据结构·算法