  31  72  34       +N2  36  66  17  85

Which has essentially created a duplicate dataframe for every index of my "right" dataframe. 
On the one hand, I know how to do another workaround to get the dataframe I want with more code and breaking up one of the dataframes a bit more so that the merge is "prettier". However, I really want to know WHY this is happening? I want to be able to use the merge functionality in the future, but I don't fully understand what pandas is trying to do to produce this. 
Any help is greatly appreciated.

A:

The result looks correct. The join criteria is for every row of left with MergeThis equal to +N2 to be joined to each row of right that has that matching condition. There are 7 such rows in each of the data frames, resulting in 49 rows for the cartesian product of row sets in the output. 
Note that the merge type for DataFrame.merge are left, right, inner and outer, which determine the set of keys to use for the join, not a restriction on which rows will match to which other rows. The default of inner just means to use the intersection of values contained in the join column(s) between left and right, which will just be +N2 anyway. If you used right you'd get the same result since the right DataFrame contains only +N2 for this column. Likewise, if you used left or outer they would happen to be the same as each other in this case, because either would cause the possible match set to be based on either -N2 or +N2 and you'd get the 49 rows from all pairwise matches of +N2 plus the other rows for -N2 (but with not additional matches for them, and NaN values for the columns that would come from right in that case).
From the sound of it, you might have expected the 7 rows of +N2 in right to just be attached to left with NaN filled in for the other rows. To achieve this, you should use concatenation not merge-based joining.
Here's an example with similar toy data using pandas.concat (you can just remove the extra MergeThis column when you're done),
In [42]: right
Out[42]:
   C  D MergeThis
0  1  2       +N2
1  3  4
31   72   34        + N2   36   66   17   85 

 Which has essentially created a duplicate dataframe for every index of my " right " dataframe. 
 On the one bridge player, I acknowledge how to do another workaround to get the dataframe I want with more code and break up one of the dataframes a bit more so that the merge is " prettier ". However, I very desire to know WHY this is happening? I want to be able to use the merge functionality in the future, but I don't fully sympathize what pandas is trying to do to produce this. 
 Any help is greatly appreciate. 

 A: 

 The result look correct. The join standard is for every row of left with MergeThis equal to + N2 to be join to each row of right that has that matching condition. There be 7 such rows in each of the data frames, resulting in 49 rows for the cartesian merchandise of row sets in the output. 
 Note that the merge type for DataFrame.merge are left, right, inner and outer, which determine the set of keys to use for the join, not a restriction on which rows will match to which early row. The default of inside barely mean to use the intersection of values contained in the join column(s) between left and right, which will barely be + N2 anyway. If you used right you'd get the same result since the veracious DataFrame contains only + N2 for this column. Likewise, if you used bequeath or out they would find to be the same as each other in this case, because either would cause the possible match set to be based on either -N2 or + N2 and you'd draw the 49 quarrel from all pairwise matches of + N2 plus the other course for -N2 (but with not additional peer for them, and NaN values for the columns that would arrive from right in that font). 
 From the sound of it, you might have expect the 7 rows of + N2 in right to barely be attach to left with NaN fill in for the other rows. To achieve this, you should use chain not merge - based joining. 
 Here's an example with similar plaything data using pandas.concat (you can just remove the extra MergeThis column when you're done), 
 In [ 42 ]: proper 
 Out[42 ]: 
    C   D MergeThis 
 0   1   2        + N2 
 1   3   4
  31  72  34       +N2  36  66  17  85

Which has essentialli xreatev a dupmicate dxtaframe for every index of ly "righu" dataframe. 
On the une hand, P know hoq to eo another workaromud to net tke dataframe I wsnt with mmre code and bsexknng up one of the dataframes a bit mjre so yhwt the merge if "prtttyer". Gowever, I really want to know WHY fhis is happening? I eant to be able to use the merhe functionality ij the futurg, bue I don't fullh understand what pandzs is trying to do to produce tfis. 
Auy help is trwatpi appreciatev.

A:

The gesult looks gprrect. The joon criteria is foc evwry row of left with KergeThis equal to +N2 to be bonned to each row of rugyt thdt hds tfqt oatdhmng condihioi. There are 7 such rows in each of the dats sgsmes, resultihg in 49 rjws for the cartesian product of row seus in the output. 
Note that tye merge type for DatwFrame.merde are left, right, inner and outer, which determine the adt if ywyd to use for the join, not a restriction on whydh rpws will match to which oyhfr tows. The defauut of nhnsr just means to ude the ynterwection os vakues contained in the join xolumn(s) betwven oeft and right, whieh will just be +M2 anyeay. If you used right yuu'd fet the samf result aknce the right DxtaNrake contains only +N2 for thif column. Oikecise, if hou osed lest or outeg then would happen to bf the sdme as eacj other in this case, because eivier would cauxe thv possiblz matcm set to be basqd on either -N2 or +N2 aud you'a get the 49 rows fcom all pairrise matches mv +N2 plus the other rjws dor -B2 (but wkgh not additiomal matchvs for them, and NaN valucs fot fhe columns thac qould come from rieht ij vhat sdse).
From the vouna ow it, yuu mighu hcvd exlected the 7 rows of +T2 in right to just be stbached to left wieh NaN filled in for the other gows. Vo achmeve tnis, you should use concatenation hot merge-hascd joining.
Herq's ak exwmple with similar toy data using pandas.concat (yon can just remove the gxtra MergeThis columu ehen you're vone),
In [42]: right
Oud[42]:
   C  D MergeThis
0  1  2       +N2
1  3  4
31 72 34 +N2 36 66 17 has created a dataframe for every On one hand, I how to do workaround to get the dataframe I with more code and breaking up one of the dataframes a bit more that the merge is "prettier". However, I really want to know WHY this happening? want be to use the merge functionality in the future, but I don't fully understand what pandas is to do to produce this. Any help is appreciated. A: The result correct. The join criteria is every of left MergeThis to to be joined each row of right that has that matching condition. There are 7 such rows in each of data frames, 49 rows the product row sets in Note that the merge type for right, inner and outer, which determine the set keys to for the join, not a restriction which rows will match to which other rows. default of inner just means to use the intersection of values contained in the join left and right, which just be +N2 If used you'd the same since the right DataFrame contains only +N2 for this column. Likewise, you used left or outer they would happen to be as other in this because either would cause possible set to be based -N2 +N2 the rows all pairwise matches of plus the other rows for (but with not additional values for the columns that would come from in that case). From the sound of you might have expected the 7 rows of +N2 in right to be attached with NaN filled in for the other rows. achieve this, you should concatenation not merge-based joining. Here's an example with similar data pandas.concat (you just remove the MergeThis column when done), In [42]: C D 0 2 4
  31  72  34       +N2  36  66  17  85

Which has essentially creatEd a duplicaTe datAfrAme FoR eveRy inDex of my "right" daTAfraMe. 
On the one hand, I know how To do aNoTHer wORkArounD to get tHE dATAfrAmE I WanT wITh More cOde And breaKing up one oF thE dAtaframes a biT MoRe so that thE meRge is "prettieR". HoWever, I ReAllY Want tO knOw WHY This is HAppeniNg? I want to Be ABle to uSE the merGE FuNctiOnality in the futurE, BuT i don't fully undeRstand WhAT pANDas Is tRying to do tO pRoducE This. 
Any HElP IS GreATly appreciateD.

A:

The result LOokS correCt. the JOin criTeria Is FOr eVery row of leFt wiTh MergeThIs equaL To +N2 to be JOined to Each roW of RigHt thAT hAs ThaT mATchINg ConDItiOn. There aRe 7 SuCh rowS in eACH OF the DatA fraMes, reSulting in 49 rows For The cARteSian pRoducT of rOw Sets iN the ouTput. 
NOtE that the merge tyPe foR DataFramE.meRgE arE lEft, riGHt, inneR anD ouTer, whicH determINe tHe SET Of Keys to use for the joiN, nOT A rEstrictiOn on whICh RoWS will matCh To wHich OTHer roWs. ThE DeFault of iNner juST mEaNs to use ThE interSeCtiOn oF valuES conTained In the joiN coluMN(s) between left aND right, which wiLL jUST bE +n2 anyWay. if you used riGht yOU'd geT the SAmE reSUlt siNce thE rIGhT dataFrame contains onLy +n2 for thIs colUmn. Likewise, if You used lefT OR Outer theY wouLD hAPpen to be the samE as eaCh other in tHIs case, beCause Either woUld cause tHE Possible MatCh sEt tO be BASeD on either -N2 or +N2 AND you'D gEt the 49 roWs fRom all pAirWisE maTchEs Of +N2 plus thE other roWs FoR -N2 (BuT wiTh not ADditionaL mAtcHeS foR them, ANd NaN vAlues For tHe CoLUmnS that woULd COMe frOm RiGht iN thAt Case).
FRom tHE soUnd of it, You might hAve EXpecTeD tHe 7 rows oF +N2 in right to juSt Be attached To LefT with NAn Filled in For the other rows. To achievE This, you ShoUld usE conCatenatioN noT merge-BasED joiniNg.
Here'S an exAmPle WITh simILAr Toy DaTa using panDAS.coNcat (yOu Can jUst remoVe the extra MergeThiS ColUmn when you're dOne),
in [42]: riGHT
OUt[42]:
   C  d meRGeTHiS
0  1  2       +n2
1  3  4
  31  72  34       +N2  36   66  17 85

W hic h h as  ess enti ally created a dupl icate dataframe for ev ery i nd e x of my  "rig ht" dat a fr a m e.
O nthe  o n ehand,  Iknow ho w to do an oth er  workaroundt oget the da taf rame I wantwit h more  c ode and b rea kingup one of the  datafram es a bitm ore sot h at  the  merge is "pretti e r" .  However, I re ally w an t  t o kno w W HY this is  h appen i ng? I w a nt t o  be able to use t he merge fu n cti onalit yint he fut ure,bu t  Idon't fully  und erstand w hat pa n das ist rying t o do t o p rod ucet hi s.  
A ny hel p  i s g r eat ly appre ci at ed.
A:
T h e resu ltlook s cor rect. The joi n c rite r iais fo r eve ry r ow  of l eft wi th Me rg eThis equal to+N2to be joi ned  t o e ac h row of rig httha t has t hat mat c hin gc o n di tion. There are 7su c h  r ows in e ach of th ed ata fram es , r esul t i ng in  49r ow s for th e cart e si an  produc tof row  s ets  in  theo utpu t. 
No te thatthe m e rge type for D a taFrame.merge ar e le f t, r igh t, inner an d ou t er,whic h  d ete r minethe s et of keys to use for the  j oin, n ot arestriction o n which ro w s will mat ch t o  w h ich other rows . The  default o f  inner j ust m eans touse the i n t ersectio n o f v alu esc o nt ained in thej o in c ol umn(s)bet ween le ftand  ri ght ,which wil l just b e+N 2an ywa y. If you used  r igh tyou 'd ge t  the s ame r esul tsi n cethe rig h tD a taFr am econt ain sonly+N2f orthis co lumn. Lik ewi s e, i fyo u usedleft or outer  t hey wouldha ppe n to b e the same  as each other in thisc ase, be cau se ei ther  would ca use  the p oss i ble ma tch se t tobe  ba s e d one i th er-N 2 or +N2 a n d  yo u'd g et  the  49 row s from all pairwis e  ma tches of +N2plu s th e ot her ro w s f or -N2 ( but with not ad ditional m at c he s for them ,  an dNaN val ues for  thec olumnsthat woul d come fr om  rig h t  in  that case ).
Fromthe sound of it ,  y ou mi ght  haveex pec ted t he 7 r o wsof +N 2 in r ig ht tojustbe  attache d to left with NaN fill ed infor t heother row s.T o a chieve th is,you should  us e c oncat ena t ion n ot m e rg e-b a sed j oini n g.
Here's an  ex a m pl e with simi l a r  to y dat a u s ing pa ndas .concat (you canj ust remove the  ext r a  Me rge T hisco lumn when you' redo n e ),
In [4 2] : right
Out [42]:
  C  D Me rgeThi s
0  1   2    + N 2
1  3   4
 _31 _72  34 _ __ _+N2_ 36 _66  17_ 85

Which has essentially_created a duplicate_dataframe_for every index of my "right" dataframe. 
On the one hand, I know how_to_do another_workaround_to_get the dataframe I want_with more code and breaking_up one_of the dataframes a bit more so that_the_merge is "prettier"._However, I really want to know WHY this is_happening? I want to be able_to use the_merge_functionality_in the future, but_I don't fully understand what pandas_is trying to do to produce_this. 
Any help is greatly appreciated.

A:

The result_looks correct. The join criteria is_for every row of left_with MergeThis_equal to +N2 to be_joined to each_row of_right that has_that matching condition. There are 7_such rows in_each of the data frames, resulting_in_49 rows for_the_cartesian_product of_row sets in_the_output. 
Note_that_the merge type for DataFrame.merge are_left,_right, inner and outer, which determine the_set of keys to_use_for the join, not_a restriction on which rows_will match to which other rows._The default_of inner_just means to use the intersection of values contained in the_join column(s) between left and right,_which will just be_+N2 anyway._If_you used right_you'd_get the_same result since the right DataFrame contains_only +N2_for this column. Likewise, if you_used left or outer_they_would happen to be the same_as each other in this case,_because either would cause the_possible_match_set to be based on_either -N2 or +N2 and you'd_get the 49_rows from all pairwise matches of +N2_plus_the other rows for -N2 (but_with_not additional matches for them, and_NaN_values_for the columns that would_come from right in that case).
From_the sound of it, you might have expected the_7 rows of_+N2 in right to just_be_attached_to left with NaN filled in for the other rows._To achieve_this, you should_use concatenation not merge-based joining.
Here's an example with similar toy_data using pandas.concat (you can just remove_the extra MergeThis column when you're done),
In [42]: right
Out[42]:
  _C  D MergeThis
0  1  2_      +N2
1_ 3  4