列表

详情


2884. Modify Columns

DataFrame employees
+-------------+--------+
| Column Name | Type   |
+-------------+--------+
| name        | object |
| salary      | int    |
+-------------+--------+

A company intends to give its employees a pay rise.

Write a solution to modify the salary column by multiplying each salary by 2.

The result format is in the following example.

 

Example 1:

Input:
DataFrame employees
+---------+--------+
| name    | salary |
+---------+--------+
| Jack    | 19666  |
| Piper   | 74754  |
| Mia     | 62509  |
| Ulysses | 54866  |
+---------+--------+
Output:
+---------+--------+
| name    | salary |
+---------+--------+
| Jack    | 39332  |
| Piper   | 149508 |
| Mia     | 125018 |
| Ulysses | 109732 |
+---------+--------+
Explanation:
Every salary has been doubled.

原站题解

去查看

上次编辑到这里,代码来自缓存 点击恢复默认模板
import pandas as pd def modifySalaryColumn(employees: pd.DataFrame) -> pd.DataFrame:

pythondata 解法, 执行用时: 512 ms, 内存消耗: 58.9 MB, 提交时间: 2023-10-07 10:40:41

'''
修改列数据
'''
import pandas as pd

def modifySalaryColumn(employees: pd.DataFrame) -> pd.DataFrame:
    employees['salary'] *= 2
    return employees

上一题