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 [3]:
# broadcasting : assume that we want to update the all column data
bank_df['Balance'] = bank_df['Balance'] + 1000
In [4]:
bank_df
Out[4]:
RowNumber | CustomerId | Surname | CreditScore | Geography | Gender | Age | Tenure | Balance | NumOfProducts | HasCrCard | IsActiveMember | EstimatedSalary | Exited | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1 | 15634602 | Hargrave | 619 | France | Female | 42 | 2 | 1000.00 | 1 | 1 | 1 | 101348.88 | 1 |
1 | 2 | 15647311 | Hill | 608 | Spain | Female | 41 | 1 | 84807.86 | 1 | 0 | 1 | 112542.58 | 0 |
2 | 3 | 15619304 | Onio | 502 | France | Female | 42 | 8 | 160660.80 | 3 | 1 | 0 | 113931.57 | 1 |
3 | 4 | 15701354 | Boni | 699 | France | Female | 39 | 1 | 1000.00 | 2 | 0 | 0 | 93826.63 | 0 |
4 | 5 | 15737888 | Mitchell | 850 | Spain | Female | 43 | 2 | 126510.82 | 1 | 1 | 1 | 79084.10 | 0 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
9995 | 9996 | 15606229 | Obijiaku | 771 | France | Male | 39 | 5 | 1000.00 | 2 | 1 | 0 | 96270.64 | 0 |
9996 | 9997 | 15569892 | Johnstone | 516 | France | Male | 35 | 10 | 58369.61 | 1 | 1 | 1 | 101699.77 | 0 |
9997 | 9998 | 15584532 | Liu | 709 | France | Female | 36 | 7 | 1000.00 | 1 | 0 | 1 | 42085.58 | 1 |
9998 | 9999 | 15682355 | Sabbatini | 772 | Germany | Male | 42 | 3 | 76075.31 | 2 | 1 | 0 | 92888.52 | 1 |
9999 | 10000 | 15628319 | Walker | 792 | France | Female | 28 | 4 | 131142.79 | 1 | 1 | 0 | 38190.78 | 0 |
10000 rows × 14 columns
In [5]:
bank_df['Balance'] = bank_df['Balance'].add(1000); bank_df
Out[5]:
RowNumber | CustomerId | Surname | CreditScore | Geography | Gender | Age | Tenure | Balance | NumOfProducts | HasCrCard | IsActiveMember | EstimatedSalary | Exited | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1 | 15634602 | Hargrave | 619 | France | Female | 42 | 2 | 2000.00 | 1 | 1 | 1 | 101348.88 | 1 |
1 | 2 | 15647311 | Hill | 608 | Spain | Female | 41 | 1 | 85807.86 | 1 | 0 | 1 | 112542.58 | 0 |
2 | 3 | 15619304 | Onio | 502 | France | Female | 42 | 8 | 161660.80 | 3 | 1 | 0 | 113931.57 | 1 |
3 | 4 | 15701354 | Boni | 699 | France | Female | 39 | 1 | 2000.00 | 2 | 0 | 0 | 93826.63 | 0 |
4 | 5 | 15737888 | Mitchell | 850 | Spain | Female | 43 | 2 | 127510.82 | 1 | 1 | 1 | 79084.10 | 0 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
9995 | 9996 | 15606229 | Obijiaku | 771 | France | Male | 39 | 5 | 2000.00 | 2 | 1 | 0 | 96270.64 | 0 |
9996 | 9997 | 15569892 | Johnstone | 516 | France | Male | 35 | 10 | 59369.61 | 1 | 1 | 1 | 101699.77 | 0 |
9997 | 9998 | 15584532 | Liu | 709 | France | Female | 36 | 7 | 2000.00 | 1 | 0 | 1 | 42085.58 | 1 |
9998 | 9999 | 15682355 | Sabbatini | 772 | Germany | Male | 42 | 3 | 77075.31 | 2 | 1 | 0 | 92888.52 | 1 |
9999 | 10000 | 15628319 | Walker | 792 | France | Female | 28 | 4 | 132142.79 | 1 | 1 | 0 | 38190.78 | 0 |
10000 rows × 14 columns
In [6]:
# 1usd = 1240krw
bank_df['Balance (krw)'] = bank_df['Balance'].mul(1240);bank_df
Out[6]:
RowNumber | CustomerId | Surname | CreditScore | Geography | Gender | Age | Tenure | Balance | NumOfProducts | HasCrCard | IsActiveMember | EstimatedSalary | Exited | Balance (krw) | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1 | 15634602 | Hargrave | 619 | France | Female | 42 | 2 | 2000.00 | 1 | 1 | 1 | 101348.88 | 1 | 2480000.0 |
1 | 2 | 15647311 | Hill | 608 | Spain | Female | 41 | 1 | 85807.86 | 1 | 0 | 1 | 112542.58 | 0 | 106401746.4 |
2 | 3 | 15619304 | Onio | 502 | France | Female | 42 | 8 | 161660.80 | 3 | 1 | 0 | 113931.57 | 1 | 200459392.0 |
3 | 4 | 15701354 | Boni | 699 | France | Female | 39 | 1 | 2000.00 | 2 | 0 | 0 | 93826.63 | 0 | 2480000.0 |
4 | 5 | 15737888 | Mitchell | 850 | Spain | Female | 43 | 2 | 127510.82 | 1 | 1 | 1 | 79084.10 | 0 | 158113416.8 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
9995 | 9996 | 15606229 | Obijiaku | 771 | France | Male | 39 | 5 | 2000.00 | 2 | 1 | 0 | 96270.64 | 0 | 2480000.0 |
9996 | 9997 | 15569892 | Johnstone | 516 | France | Male | 35 | 10 | 59369.61 | 1 | 1 | 1 | 101699.77 | 0 | 73618316.4 |
9997 | 9998 | 15584532 | Liu | 709 | France | Female | 36 | 7 | 2000.00 | 1 | 0 | 1 | 42085.58 | 1 | 2480000.0 |
9998 | 9999 | 15682355 | Sabbatini | 772 | Germany | Male | 42 | 3 | 77075.31 | 2 | 1 | 0 | 92888.52 | 1 | 95573384.4 |
9999 | 10000 | 15628319 | Walker | 792 | France | Female | 28 | 4 | 132142.79 | 1 | 1 | 0 | 38190.78 | 0 | 163857059.6 |
10000 rows × 15 columns
In [7]:
# update the tenure of a given customer
bank_df.iloc[1,7] = 3
bank_df
Out[7]:
RowNumber | CustomerId | Surname | CreditScore | Geography | Gender | Age | Tenure | Balance | NumOfProducts | HasCrCard | IsActiveMember | EstimatedSalary | Exited | Balance (krw) | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1 | 15634602 | Hargrave | 619 | France | Female | 42 | 2 | 2000.00 | 1 | 1 | 1 | 101348.88 | 1 | 2480000.0 |
1 | 2 | 15647311 | Hill | 608 | Spain | Female | 41 | 3 | 85807.86 | 1 | 0 | 1 | 112542.58 | 0 | 106401746.4 |
2 | 3 | 15619304 | Onio | 502 | France | Female | 42 | 8 | 161660.80 | 3 | 1 | 0 | 113931.57 | 1 | 200459392.0 |
3 | 4 | 15701354 | Boni | 699 | France | Female | 39 | 1 | 2000.00 | 2 | 0 | 0 | 93826.63 | 0 | 2480000.0 |
4 | 5 | 15737888 | Mitchell | 850 | Spain | Female | 43 | 2 | 127510.82 | 1 | 1 | 1 | 79084.10 | 0 | 158113416.8 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
9995 | 9996 | 15606229 | Obijiaku | 771 | France | Male | 39 | 5 | 2000.00 | 2 | 1 | 0 | 96270.64 | 0 | 2480000.0 |
9996 | 9997 | 15569892 | Johnstone | 516 | France | Male | 35 | 10 | 59369.61 | 1 | 1 | 1 | 101699.77 | 0 | 73618316.4 |
9997 | 9998 | 15584532 | Liu | 709 | France | Female | 36 | 7 | 2000.00 | 1 | 0 | 1 | 42085.58 | 1 | 2480000.0 |
9998 | 9999 | 15682355 | Sabbatini | 772 | Germany | Male | 42 | 3 | 77075.31 | 2 | 1 | 0 | 92888.52 | 1 | 95573384.4 |
9999 | 10000 | 15628319 | Walker | 792 | France | Female | 28 | 4 | 132142.79 | 1 | 1 | 0 | 38190.78 | 0 | 163857059.6 |
10000 rows × 15 columns
In [8]:
# update the Balance of two clients
bank_df.iloc[[0,3], [8]] = [6000, 12000]
bank_df
Out[8]:
RowNumber | CustomerId | Surname | CreditScore | Geography | Gender | Age | Tenure | Balance | NumOfProducts | HasCrCard | IsActiveMember | EstimatedSalary | Exited | Balance (krw) | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1 | 15634602 | Hargrave | 619 | France | Female | 42 | 2 | 6000.00 | 1 | 1 | 1 | 101348.88 | 1 | 2480000.0 |
1 | 2 | 15647311 | Hill | 608 | Spain | Female | 41 | 3 | 85807.86 | 1 | 0 | 1 | 112542.58 | 0 | 106401746.4 |
2 | 3 | 15619304 | Onio | 502 | France | Female | 42 | 8 | 161660.80 | 3 | 1 | 0 | 113931.57 | 1 | 200459392.0 |
3 | 4 | 15701354 | Boni | 699 | France | Female | 39 | 1 | 12000.00 | 2 | 0 | 0 | 93826.63 | 0 | 2480000.0 |
4 | 5 | 15737888 | Mitchell | 850 | Spain | Female | 43 | 2 | 127510.82 | 1 | 1 | 1 | 79084.10 | 0 | 158113416.8 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
9995 | 9996 | 15606229 | Obijiaku | 771 | France | Male | 39 | 5 | 2000.00 | 2 | 1 | 0 | 96270.64 | 0 | 2480000.0 |
9996 | 9997 | 15569892 | Johnstone | 516 | France | Male | 35 | 10 | 59369.61 | 1 | 1 | 1 | 101699.77 | 0 | 73618316.4 |
9997 | 9998 | 15584532 | Liu | 709 | France | Female | 36 | 7 | 2000.00 | 1 | 0 | 1 | 42085.58 | 1 | 2480000.0 |
9998 | 9999 | 15682355 | Sabbatini | 772 | Germany | Male | 42 | 3 | 77075.31 | 2 | 1 | 0 | 92888.52 | 1 | 95573384.4 |
9999 | 10000 | 15628319 | Walker | 792 | France | Female | 28 | 4 | 132142.79 | 1 | 1 | 0 | 38190.78 | 0 | 163857059.6 |
10000 rows × 15 columns
728x90
'Data Analytics with python > [Data Analysis]' 카테고리의 다른 글
[Pandas][DataFrame]S2_11_define_functions (0) | 2023.01.21 |
---|---|
[Pandas][DataFrame]S2_10_sorting_and_ordering (0) | 2023.01.21 |
[Pandas][DataFrame]S2_08_integer_index_Based_elements_selection (0) | 2023.01.21 |
[Pandas][DataFrame]S2_07_Label_Based_elements_selection (0) | 2023.01.21 |
[Pandas][DataFrame]S2_06_Column_ADDING_DELETING (0) | 2023.01.21 |
댓글