标签:mat alc div job http app 导入 9.png https
数据见github
import pandas as pd
import numpy as np
path4 = "./data/student-mat.csv"
student = pd.read_csv(path4)
student.head()
输出:
stud_alcoh = student.loc[: , "school":"guardian"]
stud_alcoh.head()
输出:
captalizer = lambda x: x.upper()
stud_alcoh[‘Fjob‘].apply(captalizer)
输出:
0 TEACHER
1 OTHER
2 OTHER
3 SERVICES
4 OTHER
5 OTHER
6 OTHER
7 TEACHER
8 OTHER
9 OTHER
10 HEALTH
11 OTHER
12 SERVICES
13 OTHER
14 OTHER
15 OTHER
16 SERVICES
17 OTHER
18 SERVICES
19 OTHER
20 OTHER
21 HEALTH
22 OTHER
23 OTHER
24 HEALTH
25 SERVICES
26 OTHER
27 SERVICES
28 OTHER
29 TEACHER
...
365 OTHER
366 SERVICES
367 SERVICES
368 SERVICES
369 TEACHER
370 SERVICES
371 SERVICES
372 AT_HOME
373 OTHER
374 OTHER
375 OTHER
376 OTHER
377 SERVICES
378 OTHER
379 OTHER
380 TEACHER
381 OTHER
382 SERVICES
383 SERVICES
384 OTHER
385 OTHER
386 AT_HOME
387 OTHER
388 SERVICES
389 OTHER
390 SERVICES
391 SERVICES
392 OTHER
393 OTHER
394 AT_HOME
Name: Fjob, dtype: object
stud_alcoh.tail()
输出:
stud_alcoh[‘Mjob‘] = stud_alcoh[‘Mjob‘].apply(captalizer)
stud_alcoh[‘Fjob‘] = stud_alcoh[‘Fjob‘].apply(captalizer)
stud_alcoh.tail()
输出:
def majority(x):
if x > 17:
return True
else:
return False
stud_alcoh[‘legal_drinker‘] = stud_alcoh[‘age‘].apply(majority)
stud_alcoh.head()
输出:
def times10(x):
if type(x) is int:
return 10 * x
return x
stud_alcoh.applymap(times10).head(10)
输出:
标签:mat alc div job http app 导入 9.png https
原文地址:https://www.cnblogs.com/xiaxuexiaoab/p/9226772.html