728x90
In [1]:
import pandas as pd
In [2]:
bank_df = pd.read_csv('bank customers.csv')
bank_df
Out[2]:
RowNumber | CustomerId | Surname | CreditScore | Geography | Gender | Age | Tenure | Balance | NumOfProducts | HasCrCard | IsActiveMember | EstimatedSalary | Exited | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1 | 15634602 | Hargrave | 619 | France | Female | 42 | 2 | 0.00 | 1 | 1 | 1 | 101348.88 | 1 |
1 | 2 | 15647311 | Hill | 608 | Spain | Female | 41 | 1 | 83807.86 | 1 | 0 | 1 | 112542.58 | 0 |
2 | 3 | 15619304 | Onio | 502 | France | Female | 42 | 8 | 159660.80 | 3 | 1 | 0 | 113931.57 | 1 |
3 | 4 | 15701354 | Boni | 699 | France | Female | 39 | 1 | 0.00 | 2 | 0 | 0 | 93826.63 | 0 |
4 | 5 | 15737888 | Mitchell | 850 | Spain | Female | 43 | 2 | 125510.82 | 1 | 1 | 1 | 79084.10 | 0 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
9995 | 9996 | 15606229 | Obijiaku | 771 | France | Male | 39 | 5 | 0.00 | 2 | 1 | 0 | 96270.64 | 0 |
9996 | 9997 | 15569892 | Johnstone | 516 | France | Male | 35 | 10 | 57369.61 | 1 | 1 | 1 | 101699.77 | 0 |
9997 | 9998 | 15584532 | Liu | 709 | France | Female | 36 | 7 | 0.00 | 1 | 0 | 1 | 42085.58 | 1 |
9998 | 9999 | 15682355 | Sabbatini | 772 | Germany | Male | 42 | 3 | 75075.31 | 2 | 1 | 0 | 92888.52 | 1 |
9999 | 10000 | 15628319 | Walker | 792 | France | Female | 28 | 4 | 130142.79 | 1 | 1 | 0 | 38190.78 | 0 |
10000 rows × 14 columns
In [9]:
# A function that increases all clients balance by a fixed value of 10%
def Balance_update(balance):
return balance * 1.1
In [10]:
bank_df['Balance'] = bank_df['Balance'].apply(Balance_update)
bank_df
Out[10]:
RowNumber | CustomerId | Surname | CreditScore | Geography | Gender | Age | Tenure | Balance | NumOfProducts | HasCrCard | IsActiveMember | EstimatedSalary | Exited | Rank | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1 | 15634602 | Hargrave | 619 | France | Female | 42 | 2 | 0.000 | 1 | 1 | 1 | 101348.88 | 1 | 1 |
1 | 2 | 15647311 | Hill | 608 | Spain | Female | 41 | 1 | 92188.646 | 1 | 0 | 1 | 112542.58 | 0 | 744 |
2 | 3 | 15619304 | Onio | 502 | France | Female | 42 | 8 | 175626.880 | 3 | 1 | 0 | 113931.57 | 1 | 5794 |
3 | 4 | 15701354 | Boni | 699 | France | Female | 39 | 1 | 0.000 | 2 | 0 | 0 | 93826.63 | 0 | 1 |
4 | 5 | 15737888 | Mitchell | 850 | Spain | Female | 43 | 2 | 138061.902 | 1 | 1 | 1 | 79084.10 | 0 | 3697 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
9995 | 9996 | 15606229 | Obijiaku | 771 | France | Male | 39 | 5 | 0.000 | 2 | 1 | 0 | 96270.64 | 0 | 1 |
9996 | 9997 | 15569892 | Johnstone | 516 | France | Male | 35 | 10 | 63106.571 | 1 | 1 | 1 | 101699.77 | 0 | 125 |
9997 | 9998 | 15584532 | Liu | 709 | France | Female | 36 | 7 | 0.000 | 1 | 0 | 1 | 42085.58 | 1 | 1 |
9998 | 9999 | 15682355 | Sabbatini | 772 | Germany | Male | 42 | 3 | 82582.841 | 2 | 1 | 0 | 92888.52 | 1 | 428 |
9999 | 10000 | 15628319 | Walker | 792 | France | Female | 28 | 4 | 143157.069 | 1 | 1 | 0 | 38190.78 | 0 | 4113 |
10000 rows × 15 columns
In [11]:
bank_df['Name Length'] = bank_df['Surname'].apply(len)
bank_df
Out[11]:
RowNumber | CustomerId | Surname | CreditScore | Geography | Gender | Age | Tenure | Balance | NumOfProducts | HasCrCard | IsActiveMember | EstimatedSalary | Exited | Rank | Name Length | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1 | 15634602 | Hargrave | 619 | France | Female | 42 | 2 | 0.000 | 1 | 1 | 1 | 101348.88 | 1 | 1 | 8 |
1 | 2 | 15647311 | Hill | 608 | Spain | Female | 41 | 1 | 92188.646 | 1 | 0 | 1 | 112542.58 | 0 | 744 | 4 |
2 | 3 | 15619304 | Onio | 502 | France | Female | 42 | 8 | 175626.880 | 3 | 1 | 0 | 113931.57 | 1 | 5794 | 4 |
3 | 4 | 15701354 | Boni | 699 | France | Female | 39 | 1 | 0.000 | 2 | 0 | 0 | 93826.63 | 0 | 1 | 4 |
4 | 5 | 15737888 | Mitchell | 850 | Spain | Female | 43 | 2 | 138061.902 | 1 | 1 | 1 | 79084.10 | 0 | 3697 | 8 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
9995 | 9996 | 15606229 | Obijiaku | 771 | France | Male | 39 | 5 | 0.000 | 2 | 1 | 0 | 96270.64 | 0 | 1 | 8 |
9996 | 9997 | 15569892 | Johnstone | 516 | France | Male | 35 | 10 | 63106.571 | 1 | 1 | 1 | 101699.77 | 0 | 125 | 9 |
9997 | 9998 | 15584532 | Liu | 709 | France | Female | 36 | 7 | 0.000 | 1 | 0 | 1 | 42085.58 | 1 | 1 | 3 |
9998 | 9999 | 15682355 | Sabbatini | 772 | Germany | Male | 42 | 3 | 82582.841 | 2 | 1 | 0 | 92888.52 | 1 | 428 | 9 |
9999 | 10000 | 15628319 | Walker | 792 | France | Female | 28 | 4 | 143157.069 | 1 | 1 | 0 | 38190.78 | 0 | 4113 | 6 |
10000 rows × 16 columns
728x90
'Data Analytics with python > [Data Analysis]' 카테고리의 다른 글
[Pandas][DataFrame]S2_13_FeatureEngineering (0) | 2023.01.21 |
---|---|
[Pandas][DataFrame]S2_12_Operations_Filtering (0) | 2023.01.21 |
[Pandas][DataFrame]S2_10_sorting_and_ordering (0) | 2023.01.21 |
[Pandas][DataFrame]S2_09_Broadcasting (0) | 2023.01.21 |
[Pandas][DataFrame]S2_08_integer_index_Based_elements_selection (0) | 2023.01.21 |
댓글