mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
59 lines
4.8 KiB
JSON
59 lines
4.8 KiB
JSON
{
|
|
"data": {
|
|
"question": {
|
|
"questionId": "3072",
|
|
"questionFrontendId": "2889",
|
|
"boundTopicId": null,
|
|
"title": "Reshape Data: Pivot",
|
|
"titleSlug": "reshape-data-pivot",
|
|
"content": "<pre>\nDataFrame <code>weather</code>\n+-------------+--------+\n| Column Name | Type |\n+-------------+--------+\n| city | object |\n| month | object |\n| temperature | int |\n+-------------+--------+\n</pre>\n\n<p>Write a solution to <strong>pivot</strong> the data so that each row represents temperatures for a specific month, and each city is a separate column.</p>\n\n<p>The result format is in the following example.</p>\n\n<p> </p>\n<pre>\n<strong class=\"example\">Example 1:</strong>\n<strong>Input:</strong>\n+--------------+----------+-------------+\n| city | month | temperature |\n+--------------+----------+-------------+\n| Jacksonville | January | 13 |\n| Jacksonville | February | 23 |\n| Jacksonville | March | 38 |\n| Jacksonville | April | 5 |\n| Jacksonville | May | 34 |\n| ElPaso | January | 20 |\n| ElPaso | February | 6 |\n| ElPaso | March | 26 |\n| ElPaso | April | 2 |\n| ElPaso | May | 43 |\n+--------------+----------+-------------+\n<strong>Output:</strong><code>\n+----------+--------+--------------+\n| month | ElPaso | Jacksonville |\n+----------+--------+--------------+\n| April | 2 | 5 |\n| February | 6 | 23 |\n| January | 20 | 13 |\n| March | 26 | 38 |\n| May | 43 | 34 |\n+----------+--------+--------------+</code>\n<strong>Explanation:\n</strong>The table is pivoted, each column represents a city, and each row represents a specific month.</pre>\n",
|
|
"translatedTitle": null,
|
|
"translatedContent": null,
|
|
"isPaidOnly": false,
|
|
"difficulty": "Easy",
|
|
"likes": 33,
|
|
"dislikes": 6,
|
|
"isLiked": null,
|
|
"similarQuestions": "[]",
|
|
"exampleTestcases": "{\"headers\":{\"weather\":[\"city\",\"month\",\"temperature\"]},\"rows\":{\"weather\":[[\"Jacksonville\",\"January\",13],[\"Jacksonville\",\"February\",23],[\"Jacksonville\",\"March\",38],[\"Jacksonville\",\"April\",5],[\"Jacksonville\",\"May\",34],[\"ElPaso\",\"January\",20],[\"ElPaso\",\"February\",6],[\"ElPaso\",\"March\",26],[\"ElPaso\",\"April\",2],[\"ElPaso\",\"May\",43]]}}",
|
|
"categoryTitle": "pandas",
|
|
"contributors": [],
|
|
"topicTags": [],
|
|
"companyTagStats": null,
|
|
"codeSnippets": [
|
|
{
|
|
"lang": "Pandas",
|
|
"langSlug": "pythondata",
|
|
"code": "import pandas as pd\n\ndef pivotTable(weather: pd.DataFrame) -> pd.DataFrame:\n ",
|
|
"__typename": "CodeSnippetNode"
|
|
}
|
|
],
|
|
"stats": "{\"totalAccepted\": \"7.5K\", \"totalSubmission\": \"9.6K\", \"totalAcceptedRaw\": 7519, \"totalSubmissionRaw\": 9559, \"acRate\": \"78.7%\"}",
|
|
"hints": [
|
|
"Consider using a built-in function in pandas library to transform the data"
|
|
],
|
|
"solution": {
|
|
"id": "2106",
|
|
"canSeeDetail": true,
|
|
"paidOnly": false,
|
|
"hasVideoSolution": false,
|
|
"paidOnlyVideo": true,
|
|
"__typename": "ArticleNode"
|
|
},
|
|
"status": null,
|
|
"sampleTestCase": "{\"headers\":{\"weather\":[\"city\",\"month\",\"temperature\"]},\"rows\":{\"weather\":[[\"Jacksonville\",\"January\",13],[\"Jacksonville\",\"February\",23],[\"Jacksonville\",\"March\",38],[\"Jacksonville\",\"April\",5],[\"Jacksonville\",\"May\",34],[\"ElPaso\",\"January\",20],[\"ElPaso\",\"February\",6],[\"ElPaso\",\"March\",26],[\"ElPaso\",\"April\",2],[\"ElPaso\",\"May\",43]]}}",
|
|
"metaData": "{\n \"pythondata\": [\n \"weather = pd.DataFrame([], columns=['city', 'month', 'temperature']).astype({'city':'object', 'month':'object', 'temperature':'Int64'})\"\n ],\n \"database\": true,\n \"name\": \"pivot_table\",\n \"languages\": [\n \"pythondata\"\n ],\n \"manual\": true\n}",
|
|
"judgerAvailable": true,
|
|
"judgeType": "large",
|
|
"mysqlSchemas": [],
|
|
"enableRunCode": true,
|
|
"enableTestMode": false,
|
|
"enableDebugger": false,
|
|
"envInfo": "{\"pythondata\": [\"Pandas\", \"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0</p>\"]}",
|
|
"libraryUrl": null,
|
|
"adminUrl": null,
|
|
"challengeQuestion": null,
|
|
"__typename": "QuestionNode"
|
|
}
|
|
}
|
|
} |