-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2884-ModifyColumns.py
More file actions
50 lines (45 loc) · 1.21 KB
/
2884-ModifyColumns.py
File metadata and controls
50 lines (45 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# 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:
employees['salary'] = employees['salary'] * 2
return employees
if __name__ == "__main__":
l = [
[101, 1, 15],
[101, 2, 11],
[103, None, 11],
[104, 4, 20]
]
print(modifySalaryColumn(pd.DataFrame(l,columns=["email","name","salary"])))