No video

How to combine DataFrames in Pandas | Merge, Join, Concat, & Append

  Рет қаралды 107,823

Chart Explorers

Chart Explorers

Күн бұрын

In this video we go over how to combine DataFrames using merge, join, concat, and append. We also discuss the different join types and how to use them in pandas. It is explained how to stack DataFrames on top of one another and how to stich DataFrames together side-by-side.
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
$15 off Annual Dataquest subscription
app.dataquest.io/referral-signup/qybqz3r8/
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
Did you find this video helpful? Consider subscribing for weekly tips, tricks, and tutorials.
/ @chartexplorers
Join my Discord Server
/ discord
Reference: The Real Python
realpython.com...
0:00 Intro
1:09 Merge (side-by-side)
6:40 Join Types
8:15 Merge Errors
9:55 Join
10:43 Concat (Stack)
12:48 Append

Пікірлер: 113
@ttolu3992
@ttolu3992 Жыл бұрын
The most simplified tutorial I’ve seen about this topic, now I understand perfectly. Putting all tables and codes in discussion side by side made it easy. Thank you 🙏🏾
@manavsaxena5579
@manavsaxena5579 3 жыл бұрын
Amazing content, I am more of a visual learner and you have explained the concepts brilliantly with examples. Please keep it coming, I am gonna binge watch all yours videos. Subscribed!
@ChartExplorers
@ChartExplorers 3 жыл бұрын
Hi Manav, thanks for your kind words and support!
@chrisbagshaw5676
@chrisbagshaw5676 3 жыл бұрын
Ugh I have a deadline tomorrow and this video actually saved me
@ChartExplorers
@ChartExplorers 3 жыл бұрын
Wow, I'm glad this helped!
@akshaypatil-qq9jv
@akshaypatil-qq9jv 2 жыл бұрын
ya Saved me too 😅 Thanks
@hadidy13
@hadidy13 6 ай бұрын
Thanks so much! The only detailed explanation on KZbin, every other tutorial just write the code and you should guess what really happened.
@leongkern6746
@leongkern6746 Жыл бұрын
you just saved my final year project sir! Much respect for the concise and visual learning material
@khbye2411
@khbye2411 Жыл бұрын
Note to self1: At 10:37 the df1.join(df2, on='ID', lsuffix='_l', rsuffix='_r') is the same as df1.merge(df2, how='left', left_on='ID', right_index=True, suffixes=('_l', '_r'))
@manangoyal5026
@manangoyal5026 Жыл бұрын
Amazing video! Wish I could like it 1000s of times myself. Within 13 minutes, using rightly put graphics you've taught these 4 topics to me with such an ease, that's highly admirable! Please keep making more videos, the world could use more people like you :D
@AnilAnvesh
@AnilAnvesh 2 жыл бұрын
The best video on KZbin on #Python #Pandas Merge/Join/Concatenate/Append. Gratitude for your efforts ❤️
@ChartExplorers
@ChartExplorers 2 жыл бұрын
Thanks Anil! 😀
@PeaceAction6464
@PeaceAction6464 3 ай бұрын
Very simple and easy to understand explanation, the concept has been explained in almost the first minute
@PP-im6lu
@PP-im6lu 2 жыл бұрын
Wow. I can't believe how clear this explanation is! It helped me a lot! Just one thing though. It seems the concat (inner) is not exactly the same as the merge (default). concat (inner) seems to just get rid of the rows or the columns with NaNs, but merge would make sure there are matching values (whereas concat (inner) doesn't).
@KarlosEPM
@KarlosEPM 2 жыл бұрын
Good observation. Also, merge, unless used on index, generates an entirely new index. This can be problematic if you are dealing with large datasets and are using few columns, relying on index for identification of values (rows). In the latter case, I create a column with the indexes (I hope someone smarter and more experienced shares a better solution :p). Cheers!
@rolfbecker4512
@rolfbecker4512 3 жыл бұрын
The explanations are easy to understand and comprehensive. Perfect! I will recommend your material to my students. Thank you!
@ChartExplorers
@ChartExplorers 3 жыл бұрын
Thank you Rolf!
@anthimostsirigotis5483
@anthimostsirigotis5483 Жыл бұрын
Thank you man!!! In just 12min I managed to understand everything. I follow you from now on!
@AlexFariaOliveira
@AlexFariaOliveira Жыл бұрын
THANK YOU! I was days trying to merge 2 lists and was not finding a way your video made it all clear and half way though it I stopped and solved my problem!
@kamrulfst
@kamrulfst Жыл бұрын
Thanks for your video about merge,concate method. Its more clear to me now.
@user-zv5hu2oj6m
@user-zv5hu2oj6m 8 күн бұрын
Great video that just clear my questions!
@sashi6
@sashi6 2 жыл бұрын
Practical and concise explanation. Enjoyed watching your learning videos
@hedibena3697
@hedibena3697 Жыл бұрын
I would like to thank you for sharing this knowledge in an incredible and such easy way! This really helped me, thanks a lot!
@leulsegedmesfin7239
@leulsegedmesfin7239 Жыл бұрын
amazing explanation man,thanks.
@keifer7813
@keifer7813 Жыл бұрын
Watching this on my lunch break because my manager thinks I'm an excel whizz. She told me to run some macros but really I'm using python to clean up some excel files lmao
@ellyothim355
@ellyothim355 Жыл бұрын
Superb brother, Wish I met this channel earlier
@TippsausEuropa
@TippsausEuropa Жыл бұрын
Coooool. Clear and easy and very useful . Best regards from Technischen Universität Berlin
@trustedai
@trustedai Жыл бұрын
Excellent tutorial with lucid and simplified explanations.
@hetpatel7918
@hetpatel7918 3 жыл бұрын
I was very confused about this topic until i watched this video great explanation
@ChartExplorers
@ChartExplorers 3 жыл бұрын
That's great to hear! Thank you.
@quornnugget7799
@quornnugget7799 Жыл бұрын
At 9:20 you spoke about the data type error. I am struggling with this as my table will not change the data type no matter what I try. Do you have any fixes for this?
@splashstrike
@splashstrike 3 жыл бұрын
You're a great teacher. Subscribed.
@ChartExplorers
@ChartExplorers 3 жыл бұрын
Thanks!
@munirbhatti1103
@munirbhatti1103 10 ай бұрын
You are making too good videos, Please make more videos on python, Data science and ML. It will be really helpful. Thankyou!
@Rishabh_Sar_Di
@Rishabh_Sar_Di 2 жыл бұрын
Hey...why am I getting Error as 'You are trying to merge on float64 and object columns' while using pd.merge(df1,df2) ?? Though u could easily merge float64 and object columns !! Plzz assist
@darkmatter4701
@darkmatter4701 2 жыл бұрын
thank you for making this video it really helped with my problem that i was stuck in, thank you.
@hoaralatoan845
@hoaralatoan845 Жыл бұрын
Super clearly, a helpful explanation. Thank you so much.
@Olimpico230
@Olimpico230 Жыл бұрын
thank you so much sir, you saved me too much stress
@eldhose101
@eldhose101 Жыл бұрын
Thankyou , this really helped me to understand.
@InteligenciadeNegocios
@InteligenciadeNegocios 2 жыл бұрын
Thank you!
@talalsafaq
@talalsafaq Жыл бұрын
Ver Ver Very Good explaining ,, thank you very much
@prizepig
@prizepig Жыл бұрын
Exactly what I was looking for. Thanks!
@Nightmare78hAlo
@Nightmare78hAlo 6 ай бұрын
A note for anyone getting errors for append, apparently that is now deprecated as of 2023/2024 for pandas , ie it's not part of pandas anymore so you can ignore append.
@helengh5493
@helengh5493 2 жыл бұрын
Hi , I love the video , that was so clear and useful would you please explain what is the best way to merge and or concat the data frame which are not created in current working directory , should we read them one by one or is there any other short way?
@Puma_178
@Puma_178 2 жыл бұрын
hi, I loved your video, very clear explanation and good example, thank you
@user-ro3rw9vp4f
@user-ro3rw9vp4f Жыл бұрын
Absolutely brilliant 🔥 Thank you very much!
@TraderSam96
@TraderSam96 Жыл бұрын
Simplified,thanks alot
@keerthanasrinivas474
@keerthanasrinivas474 3 жыл бұрын
This was exactly what I needed. Thank you.
@mooventhan110
@mooventhan110 3 жыл бұрын
Neat and Clean Easy to understand Thanks man :-)
@ChartExplorers
@ChartExplorers 3 жыл бұрын
Thanks! This is something that always tripped me up, so I'm glad you found it easy to understand 😀
@josesanchezpalacios8991
@josesanchezpalacios8991 Жыл бұрын
With pd.concat([df1,df2], join='inner') I was expecting to see Col_4 once ? why is repeated ? any way of avoiding that?
@vivekshindeVivekShinde
@vivekshindeVivekShinde Жыл бұрын
amazing loved the visual explaination
@JuanPerez-iu9vk
@JuanPerez-iu9vk 3 ай бұрын
Great! Thank you very much!
@aandyrea
@aandyrea 2 жыл бұрын
Thank you SOOOO much! This was perfect!
@mohammadyahya78
@mohammadyahya78 2 жыл бұрын
Thank you very much. Very clear explanation. At 4:26 please, is there a way to avoid comparing the row that has same ID from datrafeme 1 to all these that have same ID in row 2 please?
@idongessien2245
@idongessien2245 Жыл бұрын
HI, I'm trying to merge datasets but keep getting memory error issues. How can I get pass that? Now my computer just freezes each time I attempt. I always have to forcefully shut down my laptop and reboot it all over again. still no progress made. Please help
@basicallyeditor
@basicallyeditor Жыл бұрын
Hi, I need to merge oldxl data and new xldata, label column is same in both xls I need to do outer join. If label value is same in both xls it should keep the row of new xl Can you pls help in this. Thank you
@neuralNudge123
@neuralNudge123 Жыл бұрын
hey, sooo useful tahnks. Could you please please please share the ntb?
@inthemakinh
@inthemakinh 2 жыл бұрын
if we want to merge the text in all the cells of a row or column into a single cell, or just keep the merged cell then how can we do that.
@business_central
@business_central 3 жыл бұрын
Great video and love the visuals ! Just one question, any video/explanation on merge_asof techniques
@noone-kg8ry
@noone-kg8ry 2 жыл бұрын
what if the identifiers have the same values but they don't have the same titel for example: product_id and item_id. How do i merge these sort of dataframes?
@sarthakshandilya8412
@sarthakshandilya8412 2 жыл бұрын
hey, thanx for such a good explanation 😊😊
@richarda1630
@richarda1630 3 жыл бұрын
fantastic tutorial! very well done. I was a bit confused by the "join" section starting at 10.00 It doesn't seem to be joining on the index. Could you explain that a bit more?
@ChartExplorers
@ChartExplorers 3 жыл бұрын
Thanks Richard. If you delete the on='ID' argument then it should join on the index by default. I see that you are on discord so I'll explain in more detail there.
@richarda1630
@richarda1630 3 жыл бұрын
@@ChartExplorers Thanks so much! LF to it! :)
@jananisivasankar9784
@jananisivasankar9784 2 жыл бұрын
kzbin.info... It's a great explanation on this topic..i understand it very well.. I also got confused in join topic after 10.00.. it's given on = 'ID' but default left and also inner join not happened based on the common values of that ID column..need some explanation here to understand this .pls help
@sarbanchakraborty2053
@sarbanchakraborty2053 2 жыл бұрын
Nice explanations, Thanx
@NikhilSangle
@NikhilSangle Жыл бұрын
I have to combine 34 pyspark df to one df and all df has different no of rows and only one column. Pls any one can let me know......
@kawsydaisy
@kawsydaisy Жыл бұрын
Helpful! Thank you!
@jimmyhilman5612
@jimmyhilman5612 10 ай бұрын
Cannot use df.append(), dataframe attribute append not found, any ideas ?
@rhysbennett1667
@rhysbennett1667 3 жыл бұрын
This Helped me out so much! Thank you!
@ChartExplorers
@ChartExplorers 3 жыл бұрын
I'm so glad!😀
@samt3825
@samt3825 Жыл бұрын
it was really well said
@dishantshah4383
@dishantshah4383 Жыл бұрын
Amazing Video.
@vikram2105
@vikram2105 2 жыл бұрын
Very nicely explained
@BlueSkyGoldSun
@BlueSkyGoldSun Жыл бұрын
So Join and merge are just the same in pandas and they are equivalent for SQL joins ?
@Raja-cp8uo
@Raja-cp8uo Жыл бұрын
How to add two rows when column value same in pandas?
@easydatascience2508
@easydatascience2508 Жыл бұрын
you can watch mine. The playlists provide most of the fundamentals for Python and R.
@bonefishboards
@bonefishboards 2 жыл бұрын
Perfect. Thanks!
@iliesboukhatem7803
@iliesboukhatem7803 2 жыл бұрын
a great video, thank you so much
@BridgeHK
@BridgeHK 3 жыл бұрын
Hi Your explanation is so clear and easy to follow. Do you have a Github and people can run the code directly? Thanks
@ChartExplorers
@ChartExplorers 3 жыл бұрын
Hi @Bridge2019, thank you. Here is a link to my GitHub with the code I used for the video. github.com/bvalgard/combine-dataframes
@BridgeHK
@BridgeHK 3 жыл бұрын
@@ChartExplorers Thanks! You may put the Github link under your description next time. People can access it immediately . Thanks anyway!
@ChartExplorers
@ChartExplorers 3 жыл бұрын
@@BridgeHK Great idea. Thanks!
@magi4k
@magi4k 2 жыл бұрын
Amzing explanation to be honest
@tarblood
@tarblood 2 жыл бұрын
thanks Mr.
@chilledvibes5700
@chilledvibes5700 2 жыл бұрын
very efficient video.
@freedoom4090
@freedoom4090 2 жыл бұрын
I'm geting crazy... at 7:25 : (...) f = pd.merge([zero, a], how="right") (try to run and get:) TypeError: merge() missing 1 required positional argument: 'right' I don't know what else to do. Please, someone give me a light about were's my mistake, 'cos I'm about to broke my notebook in two :(
@ChartExplorers
@ChartExplorers 2 жыл бұрын
It is looking for the second (i.e., right) dataframe. Because you added the brakets around the two dataframes it thinks it is one argument. Try it WITHOUT the brackets around your two dataframes. You want to use brakets [ ] with concat not merge. You will also need to specify what you are merging on f = pd.merge(zero, a, how='right')
@freedoom4090
@freedoom4090 2 жыл бұрын
@@ChartExplorers it worked! thanks! you saved me haha
@ChartExplorers
@ChartExplorers 2 жыл бұрын
@@freedoom4090 Awesome, I'm glad it worked!
@lala-jy4kz
@lala-jy4kz 2 жыл бұрын
Is there any source code? I want to use it as lecture notes to review.
@abegailherrera3337
@abegailherrera3337 2 жыл бұрын
Thank you 😊
@pankajgoikar4158
@pankajgoikar4158 Жыл бұрын
You are superhero
@bonnyongom1176
@bonnyongom1176 2 жыл бұрын
Nice 👍
@tindo0038
@tindo0038 Жыл бұрын
amazing
@injilaislam2275
@injilaislam2275 3 жыл бұрын
why does concat didn't match the value on basis of the column values in the inner join at 12.38
@ChartExplorers
@ChartExplorers 3 жыл бұрын
I'm not sure what you are asking? Inner join on axis = 0 will match the columns that match between both dataframes. In this case that is the ID column and Col_4. It doesn't match with the original pd.concat([df1, df2)] because the original is doing an outer join, but the 12:38 example is doing an inner join. Does that address your concern?
@injilaislam2275
@injilaislam2275 3 жыл бұрын
@@ChartExplorers hi thankyou for replying, my concern is regarding inner join, why here inner join is fetching values which are not common ,ie value from second index row, according to the law inner join only fetch common value , it more seems like outer join at 12.38
@ChartExplorers
@ChartExplorers 3 жыл бұрын
Hi @Injila Islam, good critical thinking! What is happening here is that because axis is set to 0 we are grabbing the matching values based on columns not rows. You will notice when axis=1 and join='inner' (@12:30) what you are expecting is what happens. @12:38 however it is grabbing the similar columns (ID and Col_4) that are shared between the two dataframes.
@ram-my6fl
@ram-my6fl 3 жыл бұрын
This is G.O.A.T shit
@ChartExplorers
@ChartExplorers 3 жыл бұрын
Thanks!!!
@hanyelshafey2722
@hanyelshafey2722 3 жыл бұрын
Thanks
@ChartExplorers
@ChartExplorers 3 жыл бұрын
You're welcome!
@shahzan525
@shahzan525 3 жыл бұрын
👍👍
@ryansossou646
@ryansossou646 2 жыл бұрын
note:: append going to be remove from future version of pandas
@nandineeuma6659
@nandineeuma6659 2 жыл бұрын
How to combine multiple row into single row separated with comma using python
@ChartExplorers
@ChartExplorers 2 жыл бұрын
Could you provide more details about your specific situation? Do you really want to combine rows? Or are you trying to combine columns? combining multiple columns: df['combined_columns'] = [', '.join(str(x) for x in y) for y in map(list, df[['col_1', 'col_2','col_3']].values)] For this switch out df with the name of your dataframe (two places) switch out the column names with your column names (here i have three columns but you could use more or less depending on your needs) If you are combining rows are you then appending that new row to the dataframe? or do you just want a variable to store that information? combining multiple rows: rows_combined = dfm[:5]['col_1'].values
@nandineeuma6659
@nandineeuma6659 2 жыл бұрын
@@ChartExplorers Thanks you for the response want to combine rows only for example if i combine values in A1:A5 cells and the concatenated values should be in B1 Cell, sample input is A1:X0007DFG A2:X0006FGH A3:X0005HJK OUTPUT X0007DFG,X0006FGH,X0005HJK
@richardnes1403
@richardnes1403 2 жыл бұрын
👏🏻👏🏻👏🏻
@user-nm8wf5dh2v
@user-nm8wf5dh2v Жыл бұрын
It's possible a better video than this one?
Why pros hate iterrows! | What's wrong with df.iterrows?
5:11
Chart Explorers
Рет қаралды 4,7 М.
Pandas functions: merge vs. join vs. concat
16:15
Mısra Turp
Рет қаралды 25 М.
Magic trick 🪄😁
00:13
Andrey Grechka
Рет қаралды 36 МЛН
If Barbie came to life! 💝
00:37
Meow-some! Reacts
Рет қаралды 56 МЛН
25 Nooby Pandas Coding Mistakes You Should NEVER make.
11:30
Rob Mulla
Рет қаралды 266 М.
How do I use the MultiIndex in pandas?
25:01
Data School
Рет қаралды 173 М.
My top 25 pandas tricks
27:38
Data School
Рет қаралды 267 М.
Merge, Join, Append, Concat - Pandas
11:42
Data Talks
Рет қаралды 83 М.
How do I merge DataFrames in pandas?
21:49
Data School
Рет қаралды 158 М.
Learn NUMPY in 5 minutes - BEST Python Library!
13:38
Python Programmer
Рет қаралды 841 М.
How to use groupby() to group categories in a pandas DataFrame
6:57
Chart Explorers
Рет қаралды 123 М.
Complete Python Pandas Data Science Tutorial! (2024 Updated Edition)
1:34:11