import pandas as pd
import seaborn as sns
df = sns.load_dataset('titanic')
df.head(2)
survived | pclass | sex | age | sibsp | parch | fare | embarked | class | who | adult_male | deck | embark_town | alive | alone | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 0 | 3 | male | 22.0 | 1 | 0 | 7.2500 | S | Third | man | True | NaN | Southampton | no | False |
1 | 1 | 1 | female | 38.0 | 1 | 0 | 71.2833 | C | First | woman | False | C | Cherbourg | yes | False |
df = df.loc[:, ['age', 'fare']]
df.head()
age | fare | |
---|---|---|
0 | 22.0 | 7.2500 |
1 | 38.0 | 71.2833 |
2 | 26.0 | 7.9250 |
3 | 35.0 | 53.1000 |
4 | 35.0 | 8.0500 |
def add_10(n: float) -> float:
return n + 10
df_map = df.applymap(add_10) # DataFrame의 모든 개별 원소에 함수 적용
df_map.head()
age | fare | |
---|---|---|
0 | 32.0 | 17.2500 |
1 | 48.0 | 81.2833 |
2 | 36.0 | 17.9250 |
3 | 45.0 | 63.1000 |
4 | 45.0 | 18.0500 |