Concatenation
Great! You've learned different ways of joining columns. Can we join two dataframes by rows? Surely, we can.
To join two dataframe, use the .concat()
method of pandas
, passing list of dataframes you want to join as the parameter. To perform this operation, both dataframes must have the same column names. Let's use splitted into two parts one of the dataframes used before and perform rows joining.
Note that
.concat()
is method ofpandas
, unlike the.merge()
method. So you need to usepd.concat()
.
12345678910# Importing library import pandas as pd # Loading data data1 = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/f2947b09-5f0d-4ad9-992f-ec0b87cd4b3f/section5/data_concat_1.csv') data2 = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/f2947b09-5f0d-4ad9-992f-ec0b87cd4b3f/section5/data_concat_2.csv') # Perform a left join df_res = pd.concat([data1, data2]) print(df_res)
Kiitos palautteestasi!
Kysy tekoälyä
Kysy tekoälyä
Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme
Awesome!
Completion rate improved to 2.56
Concatenation
Pyyhkäise näyttääksesi valikon
Great! You've learned different ways of joining columns. Can we join two dataframes by rows? Surely, we can.
To join two dataframe, use the .concat()
method of pandas
, passing list of dataframes you want to join as the parameter. To perform this operation, both dataframes must have the same column names. Let's use splitted into two parts one of the dataframes used before and perform rows joining.
Note that
.concat()
is method ofpandas
, unlike the.merge()
method. So you need to usepd.concat()
.
12345678910# Importing library import pandas as pd # Loading data data1 = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/f2947b09-5f0d-4ad9-992f-ec0b87cd4b3f/section5/data_concat_1.csv') data2 = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/f2947b09-5f0d-4ad9-992f-ec0b87cd4b3f/section5/data_concat_2.csv') # Perform a left join df_res = pd.concat([data1, data2]) print(df_res)
Kiitos palautteestasi!