@@ -152,7 +152,7 @@ functionality below.
152
152
Set logic on the other axes
153
153
~~~~~~~~~~~~~~~~~~~~~~~~~~~
154
154
155
- When gluing together multiple DataFrames , you have a choice of how to handle
155
+ When gluing together multiple `` DataFrame``s , you have a choice of how to handle
156
156
the other axes (other than the one being concatenated). This can be done in
157
157
the following three ways:
158
158
@@ -323,13 +323,6 @@ the name of the ``Series``.
323
323
labels = [' df1' , ' s1' ], vertical = False );
324
324
plt.close(' all' );
325
325
326
- .. note ::
327
-
328
- Since we're concatenating a ``Series `` to a ``DataFrame ``, we could have
329
- achieved the same result with :meth: `DataFrame.assign `. To concatenate an
330
- arbitrary number of pandas objects (``DataFrame `` or ``Series ``), use
331
- ``concat ``.
332
-
333
326
If unnamed ``Series `` are passed they will be numbered consecutively.
334
327
335
328
.. ipython :: python
@@ -583,7 +576,7 @@ and ``right`` is a subclass of DataFrame, the return type will still be
583
576
584
577
``merge `` is a function in the pandas namespace, and it is also available as a
585
578
``DataFrame `` instance method :meth: `~DataFrame.merge `, with the calling
586
- ``DataFrame `` being implicitly considered the left object in the join.
579
+ ``DataFrame `` being implicitly considered the left object in the join.
587
580
588
581
The related :meth:`~DataFrame.join` method, uses ``merge `` internally for the
589
582
index-on-index (by default) and column(s)-on-index join. If you are joining on
@@ -636,7 +629,7 @@ key combination:
636
629
637
630
Here is a more complicated example with multiple join keys. Only the keys
638
631
appearing in ``left `` and ``right `` are present (the intersection), since
639
- ``how='inner' `` by default.
632
+ ``how='inner'``` by default.
640
633
641
634
.. ipython:: python
642
635
@@ -721,7 +714,32 @@ either the left or right tables, the values in the joined table will be
721
714
labels = [' left' , ' right' ], vertical = False );
722
715
plt.close(' all' );
723
716
724
- Here is another example with duplicate join keys in DataFrames:
717
+ To join a Series and a DataFrame, the Series has to be transformed into a DataFrame first:
718
+
719
+ .. ipython :: python
720
+
721
+ df = pd.DataFrame({" Let" : [" A" , " B" , " C" ], " Num" : [1 , 2 , 3 ]})
722
+ df
723
+
724
+ # The series has a multi-index with levels corresponding to columns in the DataFrame we want to merge with
725
+ ser = pd.Series(
726
+ [' a' , ' b' , ' c' , ' d' , ' e' , ' f' ],
727
+ index = pd.MultiIndex.from_arrays([[" A" , " B" , " C" ]* 2 , [1 , 2 , 3 , 4 , 5 , 6 ]])
728
+ )
729
+ ser
730
+
731
+ # Name the row index levels
732
+ ser.index.names= [' Let' ,' Num' ]
733
+ ser
734
+
735
+ # reset_index turns the multi-level row index into columns, which requires a DataFrame
736
+ df2 = ser.reset_index()
737
+ type (df2)
738
+
739
+ # Now we merge the DataFrames
740
+ pd.merge(df, df2, on = [' Let' ,' Num' ])
741
+
742
+ Here is another example with duplicate join keys in ``DataFrame``s:
725
743
726
744
.. ipython:: python
727
745
@@ -1202,7 +1220,7 @@ Overlapping value columns
1202
1220
~~~~~~~~~~~~~~~~~~~~~~~~~
1203
1221
1204
1222
The merge ``suffixes `` argument takes a tuple of list of strings to append to
1205
- overlapping column names in the input ``DataFrame ``\ s to disambiguate the result
1223
+ overlapping column names in the input ``DataFrame``s to disambiguate the result
1206
1224
columns:
1207
1225
1208
1226
.. ipython:: python
0 commit comments