0

There is a data frame called release

release = pd.read_csv('release_dates.csv', index_col=None)
release.head()

then result

   title year country date
0 #73, Shaanthi Nivaasa 2007 India 2007-06-15
1 #Beings 2015 Romania 2015-01-29
2 #Declimax 2018 Netherlands 2018-01-21
3 #Ewankosau saranghaeyo 2015 Philippines 2015-01-21
4 #Horror 2015 USA 2015-11-20

We create a new data frame called c_amelia to look at specific

c_amelia = casts[ casts['title'] == 'Amelia']
c_amelia.head()

      title year name type character n
5767 Amelia 2009 Aaron Abrams actor Slim Gordon 8.0
23319 Amelia 2009 Jeremy Akerman actor Sherif

When I run the merge, the outcome is

c_amelia.merge(release).head()

   title year name type character n country date
0 Amelia 2009 Aaron Abrams actor Slim Gordon 8.0 Canada 2009-10-23
1 Amelia 2009 Aaron Abrams actor Slim Gordon 8.0 USA 2009-10-23
2 Amelia 2009 Aaron Abrams actor Slim Gordon 8.0 Australia 2009-11-12
3 Amelia 2009 Aaron Abrams actor Slim Gordon 8.0 Singapore 2009-11-12
4 Amelia 2009 Aaron Abrams actor Slim Gordon 8.0 Ireland 2009-11-13

I would like to ask how to understand this merge command? Is SQL when we want to join, we need to specify column name A = column name B. But this merge command doesn't contain any column name so how can pandas know what to merge and how?

I cannot find the answer from any other resource.

halfelf
  • 8,484
  • 13
  • 47
  • 58
NewPy
  • 458
  • 3
  • 9
  • 1
    By default, joining is done on any common column names, but you override that using various arguments. See https://stackoverflow.com/questions/53645882/pandas-merging-101 for a helpful primer on merging with pandas. Feel free to request further clarification, or vote on the answer if it was useful. Thanks. – cs95 Dec 24 '18 at 09:39
  • Thanks. I did go through the Merge 101. Greate Q&A but it didn't mention by default merge without specifying any option is joining common all columns but I got this from your comment. Thanks. I think it is quite risky to use default option without specifying column name but some column name may not have the right value we need when we just simply join based on all common columns. – NewPy Dec 25 '18 at 05:13

0 Answers0