mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
59 lines
4.4 KiB
JSON
59 lines
4.4 KiB
JSON
{
|
|
"data": {
|
|
"question": {
|
|
"questionId": "3073",
|
|
"questionFrontendId": "2890",
|
|
"boundTopicId": null,
|
|
"title": "Reshape Data: Melt",
|
|
"titleSlug": "reshape-data-melt",
|
|
"content": "<pre>\nDataFrame <code>report</code>\n+-------------+--------+\n| Column Name | Type |\n+-------------+--------+\n| product | object |\n| quarter_1 | int |\n| quarter_2 | int |\n| quarter_3 | int |\n| quarter_4 | int |\n+-------------+--------+\n</pre>\n\n<p>Write a solution to <strong>reshape</strong> the data so that each row represents sales data for a product in a specific quarter.</p>\n\n<p>The result format is in the following example.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:\n</strong>+-------------+-----------+-----------+-----------+-----------+\n| product | quarter_1 | quarter_2 | quarter_3 | quarter_4 |\n+-------------+-----------+-----------+-----------+-----------+\n| Umbrella | 417 | 224 | 379 | 611 |\n| SleepingBag | 800 | 936 | 93 | 875 |\n+-------------+-----------+-----------+-----------+-----------+\n<strong>Output:</strong>\n+-------------+-----------+-------+\n| product | quarter | sales |\n+-------------+-----------+-------+\n| Umbrella | quarter_1 | 417 |\n| SleepingBag | quarter_1 | 800 |\n| Umbrella | quarter_2 | 224 |\n| SleepingBag | quarter_2 | 936 |\n| Umbrella | quarter_3 | 379 |\n| SleepingBag | quarter_3 | 93 |\n| Umbrella | quarter_4 | 611 |\n| SleepingBag | quarter_4 | 875 |\n+-------------+-----------+-------+\n<strong>Explanation:</strong>\nThe DataFrame is reshaped from wide to long format. Each row represents the sales of a product in a quarter.\n</pre>\n",
|
|
"translatedTitle": null,
|
|
"translatedContent": null,
|
|
"isPaidOnly": false,
|
|
"difficulty": "Easy",
|
|
"likes": 32,
|
|
"dislikes": 2,
|
|
"isLiked": null,
|
|
"similarQuestions": "[]",
|
|
"exampleTestcases": "{\"headers\":{\"report\":[\"product\",\"quarter_1\",\"quarter_2\",\"quarter_3\",\"quarter_4\"]},\"rows\":{\"report\":[[\"Umbrella\",417,224,379,611],[\"SleepingBag\",800,936,93,875]]}}",
|
|
"categoryTitle": "pandas",
|
|
"contributors": [],
|
|
"topicTags": [],
|
|
"companyTagStats": null,
|
|
"codeSnippets": [
|
|
{
|
|
"lang": "Pandas",
|
|
"langSlug": "pythondata",
|
|
"code": "import pandas as pd\n\ndef meltTable(report: pd.DataFrame) -> pd.DataFrame:\n ",
|
|
"__typename": "CodeSnippetNode"
|
|
}
|
|
],
|
|
"stats": "{\"totalAccepted\": \"7.1K\", \"totalSubmission\": \"8.6K\", \"totalAcceptedRaw\": 7096, \"totalSubmissionRaw\": 8603, \"acRate\": \"82.5%\"}",
|
|
"hints": [
|
|
"Consider using a built-in function in pandas library to transform the data"
|
|
],
|
|
"solution": {
|
|
"id": "2105",
|
|
"canSeeDetail": true,
|
|
"paidOnly": false,
|
|
"hasVideoSolution": false,
|
|
"paidOnlyVideo": true,
|
|
"__typename": "ArticleNode"
|
|
},
|
|
"status": null,
|
|
"sampleTestCase": "{\"headers\":{\"report\":[\"product\",\"quarter_1\",\"quarter_2\",\"quarter_3\",\"quarter_4\"]},\"rows\":{\"report\":[[\"Umbrella\",417,224,379,611],[\"SleepingBag\",800,936,93,875]]}}",
|
|
"metaData": "{\n \"pythondata\": [\n \"report = pd.DataFrame([], columns=['product', 'quarter_1', 'quarter_2', 'quarter_3', 'quarter_4']).astype({'product':'object', 'quarter_1':'Int64', 'quarter_2':'Int64', 'quarter_3':'Int64', 'quarter_4':'Int64'})\"\n ],\n \"database\": true,\n \"name\": \"meltTable\",\n \"languages\": [\n \"pythondata\"\n ]\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"
|
|
}
|
|
}
|
|
} |