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]]
相关推荐
geovindu3 小时前
python:DecisionTree
开发语言·后端·python·算法
geovindu4 小时前
python: Decision Tree Regressor
开发语言·后端·python·算法·决策树
AIHR数智引擎5 小时前
拆掉“关键人依赖”:黄仁勋复职全员会上的四道组织切口
人工智能·经验分享·职场和发展·ai-native·英伟达·aihr
AllData公司负责人6 小时前
实战二:AllData大模型与AI数据底座-数据传输平台-DBSyncer,搭建 Http 接口同步至 Doris,API 业务数据自动拉取入数仓
大数据·数据库·数据仓库·人工智能·算法·http·doris
武子康7 小时前
火系被选七成,就应该削弱吗?
人工智能·算法·机器学习
夜不会漫长8 小时前
C++:C++11特性
开发语言·c++·算法
秋天的怀念_David8 小时前
算法一千零一夜 · 第三十七夜 · 类型的过路费
java·程序人生·算法
xckkcxxck11 小时前
Kaggle S6E10 冠军方案精读(二):245 个模型的合唱团,和一个只会“线性指挥“的老师
算法
饮水桶_T11 小时前
Git笔记
开发语言·笔记·算法