{ "data": { "question": { "questionId": "3076", "questionFrontendId": "2878", "categoryTitle": "pandas", "boundTopicId": 2467483, "title": "Get the Size of a DataFrame", "titleSlug": "get-the-size-of-a-dataframe", "content": "
\nDataFrame players:\n+-------------+--------+\n| Column Name | Type   |\n+-------------+--------+\n| player_id   | int    |\n| name        | object |\n| age         | int    |\n| position    | object |\n| ...         | ...    |\n+-------------+--------+\n
\n\n

Write a solution to calculate and display the number of rows and columns of players.

\n\n

Return the result as an array:

\n\n

[number of rows, number of columns]

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput:\n+-----------+----------+-----+-------------+--------------------+\n| player_id | name     | age | position    | team               |\n+-----------+----------+-----+-------------+--------------------+\n| 846       | Mason    | 21  | Forward     | RealMadrid         |\n| 749       | Riley    | 30  | Winger      | Barcelona          |\n| 155       | Bob      | 28  | Striker     | ManchesterUnited   |\n| 583       | Isabella | 32  | Goalkeeper  | Liverpool          |\n| 388       | Zachary  | 24  | Midfielder  | BayernMunich       |\n| 883       | Ava      | 23  | Defender    | Chelsea            |\n| 355       | Violet   | 18  | Striker     | Juventus           |\n| 247       | Thomas   | 27  | Striker     | ParisSaint-Germain |\n| 761       | Jack     | 33  | Midfielder  | ManchesterCity     |\n| 642       | Charlie  | 36  | Center-back | Arsenal            |\n+-----------+----------+-----+-------------+--------------------+\nOutput:\n[10, 5]\nExplanation:\nThis DataFrame contains 10 rows and 5 columns.\n
\n", "translatedTitle": "获取 DataFrame 的大小", "translatedContent": "
\nDataFrame players:\n+-------------+--------+\n| Column Name | Type   |\n+-------------+--------+\n| player_id   | int    |\n| name        | object |\n| age         | int    |\n| position    | object |\n| ...         | ...    |\n+-------------+--------+\n
\n\n

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

\n\n

将结果返回为一个数组:

\n\n

[number of rows, number of columns]

\n\n

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

\n\n

 

\n\n

示例 1:

\n\n
\n输入:\n+-----------+----------+-----+-------------+--------------------+\n| player_id | name     | age | position    | team               |\n+-----------+----------+-----+-------------+--------------------+\n| 846       | Mason    | 21  | Forward     | RealMadrid         |\n| 749       | Riley    | 30  | Winger      | Barcelona          |\n| 155       | Bob      | 28  | Striker     | ManchesterUnited   |\n| 583       | Isabella | 32  | Goalkeeper  | Liverpool          |\n| 388       | Zachary  | 24  | Midfielder  | BayernMunich       |\n| 883       | Ava      | 23  | Defender    | Chelsea            |\n| 355       | Violet   | 18  | Striker     | Juventus           |\n| 247       | Thomas   | 27  | Striker     | ParisSaint-Germain |\n| 761       | Jack     | 33  | Midfielder  | ManchesterCity     |\n| 642       | Charlie  | 36  | Center-back | Arsenal            |\n+-----------+----------+-----+-------------+--------------------+\n输出:\n[10, 5]\n解释:\n这个 DataFrame 包含 10 行和 5 列。\n
\n", "isPaidOnly": false, "difficulty": "Easy", "likes": 0, "dislikes": 0, "isLiked": null, "similarQuestions": "[]", "contributors": [], "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", "topicTags": [], "companyTagStats": null, "codeSnippets": [ { "lang": "Pandas", "langSlug": "pythondata", "code": "import pandas as pd\n\ndef getDataframeSize(players: pd.DataFrame) -> List[int]:\n ", "__typename": "CodeSnippetNode" } ], "stats": "{\"totalAccepted\": \"2.1K\", \"totalSubmission\": \"2.5K\", \"totalAcceptedRaw\": 2088, \"totalSubmissionRaw\": 2472, \"acRate\": \"84.5%\"}", "hints": [ "Consider using a built-in function in pandas library to get the size of a DataFrame." ], "solution": null, "status": null, "sampleTestCase": "{\"headers\":{\"players\":[\"player_id\",\"name\",\"age\",\"position\",\"team\"]},\"rows\":{\"players\":[[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\"]]}}", "metaData": "{\n \"pythondata\": [\n \"players = pd.DataFrame([], columns=['player_id', 'name', 'age', 'position', 'team']).astype({'player_id':'Int64', 'name':'object', 'age':'Int64', 'position':'object', 'team':'object'})\"\n ],\n \"database\": true,\n \"name\": \"get_size\",\n \"languages\": [\n \"pythondata\"\n ],\n \"manual\": true\n}", "judgerAvailable": true, "judgeType": "large", "mysqlSchemas": [], "enableRunCode": true, "envInfo": "{\"pythondata\":[\"Pandas\",\"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"]}", "book": null, "isSubscribed": false, "isDailyQuestion": false, "dailyRecordStatus": null, "editorType": "CKEDITOR", "ugcQuestionId": null, "style": "LEETCODE", "exampleTestcases": "{\"headers\":{\"players\":[\"player_id\",\"name\",\"age\",\"position\",\"team\"]},\"rows\":{\"players\":[[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\"]]}}", "__typename": "QuestionNode" } } }