{ "data": { "question": { "questionId": "3066", "questionFrontendId": "2881", "categoryTitle": "pandas", "boundTopicId": 2394353, "title": "Create a New Column", "titleSlug": "create-a-new-column", "content": "
\nDataFrame employees
\n+-------------+--------+\n| Column Name | Type. |\n+-------------+--------+\n| name | object |\n| salary | int. |\n+-------------+--------+\n
\n\nA company plans to provide its employees with a bonus.
\n\nWrite a solution to create a new column name bonus
that contains the doubled values of the salary
column.
The result format is in the following example.
\n\n\n
Example 1:
\n\n\nInput:\nDataFrame employees\n+---------+--------+\n| name | salary |\n+---------+--------+\n| Piper | 4548 |\n| Grace | 28150 |\n| Georgia | 1103 |\n| Willow | 6593 |\n| Finn | 74576 |\n| Thomas | 24433 |\n+---------+--------+\nOutput:\n+---------+--------+--------+\n| name | salary | bonus |\n+---------+--------+--------+\n| Piper | 4548 | 9096 |\n| Grace | 28150 | 56300 |\n| Georgia | 1103 | 2206 |\n| Willow | 6593 | 13186 |\n| Finn | 74576 | 149152 |\n| Thomas | 24433 | 48866 |\n+---------+--------+--------+\nExplanation: \nA new column bonus is created by doubling the value in the column salary.\n", "translatedTitle": "创建新列", "translatedContent": "
\nDataFrame employees
\n+-------------+--------+\n| Column Name | Type. |\n+-------------+--------+\n| name | object |\n| salary | int. |\n+-------------+--------+\n
\n\n一家公司计划为员工提供奖金。
\n\n编写一个解决方案,创建一个名为 bonus
的新列,其中包含 salary
值的 两倍。
返回结果格式如下示例所示。
\n\n\n\n
示例 1:
\n\n\n输入:\nDataFrame employees\n+---------+--------+\n| name | salary |\n+---------+--------+\n| Piper | 4548 |\n| Grace | 28150 |\n| Georgia | 1103 |\n| Willow | 6593 |\n| Finn | 74576 |\n| Thomas | 24433 |\n+---------+--------+\n输出:\n+---------+--------+--------+\n| name | salary | bonus |\n+---------+--------+--------+\n| Piper | 4548 | 9096 |\n| Grace | 28150 | 56300 |\n| Georgia | 1103 | 2206 |\n| Willow | 593 | 13186 |\n| Finn | 74576 | 149152 |\n| Thomas | 24433 | 48866 |\n+---------+--------+--------+\n解释:\n通过将 salary 列中的值加倍创建了一个新的 bonus 列。\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 createBonusColumn(employees: pd.DataFrame) -> pd.DataFrame:\n ", "__typename": "CodeSnippetNode" } ], "stats": "{\"totalAccepted\": \"1.6K\", \"totalSubmission\": \"1.8K\", \"totalAcceptedRaw\": 1626, \"totalSubmissionRaw\": 1838, \"acRate\": \"88.5%\"}", "hints": [ "Consider using the `[]` brackets with the new column name at the left side of the assignment. The calculation of the value is done element-wise." ], "solution": null, "status": null, "sampleTestCase": "{\"headers\":{\"employees\":[\"name\",\"salary\"]},\"rows\":{\"employees\":[[\"Piper\",4548],[\"Grace\",28150],[\"Georgia\",1103],[\"Willow\",6593],[\"Finn\",74576],[\"Thomas\",24433]]}}", "metaData": "{\n \"pythondata\": [\n \"employees = pd.DataFrame([], columns=['name', 'salary']).astype({'name':'object', 'salary':'Int64'})\"\n ],\n \"database\": true,\n \"name\": \"createBonusColumn\",\n \"languages\": [\n \"pythondata\"\n ]\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\":{\"employees\":[\"name\",\"salary\"]},\"rows\":{\"employees\":[[\"Piper\",4548],[\"Grace\",28150],[\"Georgia\",1103],[\"Willow\",6593],[\"Finn\",74576],[\"Thomas\",24433]]}}", "__typename": "QuestionNode" } } }