728x90
In [1]:
import pandas as pd
In [2]:
raw_data = {'Bank Client ID': ['1', '2', '3', '4', '5'],
'First Name': ['Robert', 'Benedict', 'Mark', 'Tom', 'Ryan'],
'Last Name': ['Downey', 'Cumberbatch', 'Ruffalo', 'Holland', 'Reynolds']}
bank1_df = pd.DataFrame(raw_data, columns = ['Bank Client ID', 'First Name', 'Last Name'])
bank1_df
Out[2]:
Bank Client ID | First Name | Last Name | |
---|---|---|---|
0 | 1 | Robert | Downey |
1 | 2 | Benedict | Cumberbatch |
2 | 3 | Mark | Ruffalo |
3 | 4 | Tom | Holland |
4 | 5 | Ryan | Reynolds |
In [3]:
raw_data = {'Bank Client ID': ['6', '7', '8', '9', '10'],
'First Name': ['Keanu', 'Vin', 'Chris', 'Tom', 'Dave'],
'Last Name': ['Reeves', 'Diesel', 'Pratt', 'Cruise', 'Batista']}
bank2_df = pd.DataFrame(raw_data, columns = ['Bank Client ID', 'First Name', 'Last Name'])
bank2_df
Out[3]:
Bank Client ID | First Name | Last Name | |
---|---|---|---|
0 | 6 | Keanu | Reeves |
1 | 7 | Vin | Diesel |
2 | 8 | Chris | Pratt |
3 | 9 | Tom | Cruise |
4 | 10 | Dave | Batista |
In [4]:
# indexes from both dataframes are kept unchanged
bank_all_df = pd.concat([bank1_df,bank2_df])
bank_all_df
Out[4]:
Bank Client ID | First Name | Last Name | |
---|---|---|---|
0 | 1 | Robert | Downey |
1 | 2 | Benedict | Cumberbatch |
2 | 3 | Mark | Ruffalo |
3 | 4 | Tom | Holland |
4 | 5 | Ryan | Reynolds |
0 | 6 | Keanu | Reeves |
1 | 7 | Vin | Diesel |
2 | 8 | Chris | Pratt |
3 | 9 | Tom | Cruise |
4 | 10 | Dave | Batista |
In [5]:
bank_all_df = pd.concat([bank1_df,bank2_df], ignore_index = True)
bank_all_df
Out[5]:
Bank Client ID | First Name | Last Name | |
---|---|---|---|
0 | 1 | Robert | Downey |
1 | 2 | Benedict | Cumberbatch |
2 | 3 | Mark | Ruffalo |
3 | 4 | Tom | Holland |
4 | 5 | Ryan | Reynolds |
5 | 6 | Keanu | Reeves |
6 | 7 | Vin | Diesel |
7 | 8 | Chris | Pratt |
8 | 9 | Tom | Cruise |
9 | 10 | Dave | Batista |
In [7]:
bank_all_df = bank1_df.append(bank2_df, ignore_index=True)
bank_all_df
Out[7]:
Bank Client ID | First Name | Last Name | |
---|---|---|---|
0 | 1 | Robert | Downey |
1 | 2 | Benedict | Cumberbatch |
2 | 3 | Mark | Ruffalo |
3 | 4 | Tom | Holland |
4 | 5 | Ryan | Reynolds |
5 | 6 | Keanu | Reeves |
6 | 7 | Vin | Diesel |
7 | 8 | Chris | Pratt |
8 | 9 | Tom | Cruise |
9 | 10 | Dave | Batista |
728x90
'Data Analytics with python > [Data Analysis]' 카테고리의 다른 글
[Pandas][DataFrame][MultiIndex]S4_01_Explore_dataset (0) | 2023.01.21 |
---|---|
[Pandas][DataFrame][concat]S3_02_concatenation_with_multi_indexing (0) | 2023.01.21 |
[Pandas][DataFrame]S2_14_change_datatypes (0) | 2023.01.21 |
[Pandas][DataFrame]S2_13_FeatureEngineering (0) | 2023.01.21 |
[Pandas][DataFrame]S2_12_Operations_Filtering (0) | 2023.01.21 |
댓글