-
Notifications
You must be signed in to change notification settings - Fork 1
/
map
62 lines (44 loc) · 1.36 KB
/
map
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
51
52
53
54
55
56
57
58
59
60
61
62
# map is a good way to fill or replace the data that meet certain requirement you set---
missing_continents={'Korea':'Asia','Russian Federation': 'Europe',
'Slovak Republic': 'Europe'}
merged['Country'].map(missing_continents)
merged['Continent']=merged['Continent'].fillna(merged['Country'].map(missing_continents))
#将-8转换为3
train['happiness'] = train['happiness'].map(lambda x: 3 if x==-8 else x)
train['happiness'] = train['happiness'].map(lambda x:x-1)
# minus one for each row of this column
def birth_split(x):
if 1920<=x<=1930:
return 0
elif 1930<x<=1940:
return 1
elif 1940<x<=1950:
return 2
elif 1950<x<=1960:
return 3
elif 1960<x<=1970:
return 4
elif 1970<x<=1980:
return 5
elif 1980<x<=1990:
return 6
elif 1990<x<=2000:
return 7
data["birth_s"]=data["birth"].map(birth_split)
# use map for dataframe
def factorial(n):
return 1 if n<2 else n*factorial(n-1)
print(list(map(factorial,range(5))))
print([factorial(n) for n in range(6)])
print([factorial(n) for n in range(6) if n%2])
s= 12312
print(list(map(int,str(s))))
# [1, 2, 3, 1, 2]
print(list(map(int,(1,2,3))))
print(list(map(int,'1256')))
def powers(x,y,z):
return x**2+y**2+z**2
listone = [1,2,3]
listtwo = [1,1,1]
listthree = [2,2,2]
print(list(map(powers,listone,listtwo,listthree)))