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

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 ก.ค. 2024
  • 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/pandas-merge-j...
    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
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 112

  • @ttolu3992
    @ttolu3992 ปีที่แล้ว +13

    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 🙏🏾

  • @leongkern6746
    @leongkern6746 ปีที่แล้ว +3

    you just saved my final year project sir! Much respect for the concise and visual learning material

  • @manangoyal5026
    @manangoyal5026 ปีที่แล้ว +2

    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

  • @hadidy13
    @hadidy13 5 หลายเดือนก่อน

    Thanks so much!
    The only detailed explanation on TH-cam, every other tutorial just write the code and you should guess what really happened.

  • @anthimostsirigotis5483
    @anthimostsirigotis5483 ปีที่แล้ว

    Thank you man!!! In just 12min I managed to understand everything. I follow you from now on!

  • @rolfbecker4512
    @rolfbecker4512 3 ปีที่แล้ว +4

    The explanations are easy to understand and comprehensive. Perfect! I will recommend your material to my students. Thank you!

  • @manavsaxena5579
    @manavsaxena5579 3 ปีที่แล้ว +24

    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!

  • @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!

  • @hedibena3697
    @hedibena3697 ปีที่แล้ว +1

    I would like to thank you for sharing this knowledge in an incredible and such easy way! This really helped me, thanks a lot!

  • @chrisbagshaw5676
    @chrisbagshaw5676 3 ปีที่แล้ว +18

    Ugh I have a deadline tomorrow and this video actually saved me

  • @sashi6
    @sashi6 2 ปีที่แล้ว +1

    Practical and concise explanation.
    Enjoyed watching your learning videos

  • @AnilAnvesh
    @AnilAnvesh 2 ปีที่แล้ว +4

    The best video on TH-cam on #Python #Pandas Merge/Join/Concatenate/Append.
    Gratitude for your efforts ❤️

  • @PeaceAction6464
    @PeaceAction6464 2 หลายเดือนก่อน

    Very simple and easy to understand explanation, the concept has been explained in almost the first minute

  • @trustedai
    @trustedai ปีที่แล้ว

    Excellent tutorial with lucid and simplified explanations.

  • @kamrulfst
    @kamrulfst ปีที่แล้ว

    Thanks for your video about merge,concate method. Its more clear to me now.

  • @keerthanasrinivas474
    @keerthanasrinivas474 3 ปีที่แล้ว

    This was exactly what I needed. Thank you.

  • @PP-im6lu
    @PP-im6lu 2 ปีที่แล้ว +4

    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 ปีที่แล้ว +1

      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!

  • @darkmatter4701
    @darkmatter4701 2 ปีที่แล้ว

    thank you for making this video it really helped with my problem that i was stuck in, thank you.

  • @leulsegedmesfin7239
    @leulsegedmesfin7239 ปีที่แล้ว +1

    amazing explanation man,thanks.

  • @hoaralatoan845
    @hoaralatoan845 ปีที่แล้ว

    Super clearly, a helpful explanation. Thank you so much.

  • @prizepig
    @prizepig ปีที่แล้ว

    Exactly what I was looking for. Thanks!

  • @user-ro3rw9vp4f
    @user-ro3rw9vp4f ปีที่แล้ว

    Absolutely brilliant 🔥 Thank you very much!

  • @aandyrea
    @aandyrea 2 ปีที่แล้ว

    Thank you SOOOO much! This was perfect!

  • @Puma_178
    @Puma_178 2 ปีที่แล้ว

    hi, I loved your video, very clear explanation and good example, thank you

  • @splashstrike
    @splashstrike 3 ปีที่แล้ว +2

    You're a great teacher. Subscribed.

  • @rhysbennett1667
    @rhysbennett1667 3 ปีที่แล้ว

    This Helped me out so much! Thank you!

  • @eldhose101
    @eldhose101 ปีที่แล้ว

    Thankyou , this really helped me to understand.

  • @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.

  • @vivekshindeVivekShinde
    @vivekshindeVivekShinde ปีที่แล้ว

    amazing
    loved the visual explaination

  • @khbye2411
    @khbye2411 ปีที่แล้ว +3

    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'))

  • @ellyothim355
    @ellyothim355 ปีที่แล้ว

    Superb brother,
    Wish I met this channel earlier

  • @JuanPerez-iu9vk
    @JuanPerez-iu9vk 3 หลายเดือนก่อน

    Great! Thank you very much!

  • @kawsydaisy
    @kawsydaisy ปีที่แล้ว

    Helpful! Thank you!

  • @Olimpico230
    @Olimpico230 ปีที่แล้ว

    thank you so much sir, you saved me too much stress

  • @mooventhan110
    @mooventhan110 3 ปีที่แล้ว +1

    Neat and Clean
    Easy to understand
    Thanks man :-)

    • @ChartExplorers
      @ChartExplorers  3 ปีที่แล้ว +1

      Thanks! This is something that always tripped me up, so I'm glad you found it easy to understand 😀

  • @TippsausEuropa
    @TippsausEuropa ปีที่แล้ว

    Coooool.
    Clear and easy and very useful .
    Best regards from Technischen Universität Berlin

  • @TraderSam96
    @TraderSam96 ปีที่แล้ว

    Simplified,thanks alot

  • @helengh5493
    @helengh5493 2 ปีที่แล้ว +1

    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?

  • @sarthakshandilya8412
    @sarthakshandilya8412 2 ปีที่แล้ว

    hey, thanx for such a good explanation 😊😊

  • @talalsafaq
    @talalsafaq ปีที่แล้ว

    Ver Ver Very Good explaining ,, thank you very much

  • @InteligenciadeNegocios
    @InteligenciadeNegocios 2 ปีที่แล้ว +2

    Thank you!

  • @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?

  • @sarbanchakraborty2053
    @sarbanchakraborty2053 2 ปีที่แล้ว

    Nice explanations, Thanx

  • @iliesboukhatem7803
    @iliesboukhatem7803 2 ปีที่แล้ว

    a great video, thank you so much

  • @samt3825
    @samt3825 ปีที่แล้ว

    it was really well said

  • @dishantshah4383
    @dishantshah4383 ปีที่แล้ว

    Amazing Video.

  • @bonefishboards
    @bonefishboards 2 ปีที่แล้ว

    Perfect. Thanks!

  • @business_central
    @business_central 3 ปีที่แล้ว

    Great video and love the visuals !
    Just one question, any video/explanation on merge_asof techniques

  • @vikram2105
    @vikram2105 2 ปีที่แล้ว

    Very nicely explained

  • @munirbhatti1103
    @munirbhatti1103 9 หลายเดือนก่อน

    You are making too good videos, Please make more videos on python, Data science and ML.
    It will be really helpful. Thankyou!

  • @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

  • @chilledvibes5700
    @chilledvibes5700 2 ปีที่แล้ว

    very efficient video.

  • @tarblood
    @tarblood 2 ปีที่แล้ว

    thanks Mr.

  • @quornnugget7799
    @quornnugget7799 ปีที่แล้ว +1

    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?

  • @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?

  • @abegailherrera3337
    @abegailherrera3337 2 ปีที่แล้ว

    Thank you 😊

  • @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?

  • @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.

  • @Rishabh_Sar_Di
    @Rishabh_Sar_Di 2 ปีที่แล้ว +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

  • @bonnyongom1176
    @bonnyongom1176 ปีที่แล้ว

    Nice 👍

  • @tindo0038
    @tindo0038 ปีที่แล้ว

    amazing

  • @BlueSkyGoldSun
    @BlueSkyGoldSun ปีที่แล้ว

    So Join and merge are just the same in pandas and they are equivalent for SQL joins ?

  • @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

  • @jimmyhilman5612
    @jimmyhilman5612 10 หลายเดือนก่อน

    Cannot use df.append(), dataframe attribute append not found, any ideas ?

  • @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......

  • @pankajgoikar4158
    @pankajgoikar4158 ปีที่แล้ว

    You are superhero

  • @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

  • @magi4k
    @magi4k 2 ปีที่แล้ว

    Amzing explanation to be honest

  • @lala-jy4kz
    @lala-jy4kz 2 ปีที่แล้ว

    Is there any source code? I want to use it as lecture notes to review.

  • @hanyelshafey2722
    @hanyelshafey2722 3 ปีที่แล้ว +1

    Thanks

  • @richarda1630
    @richarda1630 3 ปีที่แล้ว +1

    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 ปีที่แล้ว +1

      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 ปีที่แล้ว +1

      @@ChartExplorers Thanks so much! LF to it! :)

    • @jananisivasankar9784
      @jananisivasankar9784 2 ปีที่แล้ว

      th-cam.com/users/ChartExplorers... 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

  • @Raja-cp8uo
    @Raja-cp8uo ปีที่แล้ว +1

    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.

  • @Nightmare78hAlo
    @Nightmare78hAlo 5 หลายเดือนก่อน

    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.

  • @BridgeHK
    @BridgeHK 3 ปีที่แล้ว +1

    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 ปีที่แล้ว +1

      @@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!

  • @shahzan525
    @shahzan525 3 ปีที่แล้ว +2

    👍👍

  • @richardnes1403
    @richardnes1403 2 ปีที่แล้ว

    👏🏻👏🏻👏🏻

  • @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.

  • @freedoom4090
    @freedoom4090 2 ปีที่แล้ว +1

    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!

  • @ram-my6fl
    @ram-my6fl 3 ปีที่แล้ว +1

    This is G.O.A.T shit

  • @nandineeuma6659
    @nandineeuma6659 2 ปีที่แล้ว

    How to combine multiple row into single row separated with comma using python

    • @ChartExplorers
      @ChartExplorers  2 ปีที่แล้ว +3

      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

  • @ryansossou646
    @ryansossou646 ปีที่แล้ว

    note:: append going to be remove from future version of pandas

  • @user-nm8wf5dh2v
    @user-nm8wf5dh2v ปีที่แล้ว

    It's possible a better video than this one?