@@ -325,6 +325,28 @@ for converting text to upper, lower, and title case, respectively.
325
325
.. include :: includes/case.rst
326
326
327
327
328
+ Merging
329
+ -------
330
+
331
+ .. include :: includes/merge_setup.rst
332
+
333
+ In Excel, there are `merging of tables can be done through a VLOOKUP
334
+ <https://support.microsoft.com/en-us/office/how-can-i-merge-two-or-more-tables-c80a9fce-c1ab-4425-bb96-497dd906d656> `_.
335
+
336
+ .. image :: ../../_static/spreadsheets/vlookup.png
337
+ :alt: Screenshot showing a VLOOKUP formula between two tables in Excel, with some values being filled in and others with "#N/A"
338
+ :align: center
339
+
340
+ .. include :: includes/merge.rst
341
+
342
+ ``merge `` has a number of advantages over ``VLOOKUP ``:
343
+
344
+ * The lookup value doesn't need to be the first column of the lookup table
345
+ * If multiple rows are matched, there will be one row for each match, instead of just the first
346
+ * It will include all columns from the lookup table, instead of just a single specified column
347
+ * It supports :ref: `more complex join operations <merging.join >`
348
+
349
+
328
350
Other considerations
329
351
--------------------
330
352
@@ -390,44 +412,6 @@ The equivalent in pandas:
390
412
tips, values = " tip" , index = [" size" ], columns = [" sex" ], aggfunc = np.average
391
413
)
392
414
393
- VLOOKUP
394
- ~~~~~~~
395
-
396
- .. ipython :: python
397
-
398
- import random
399
-
400
- first_names = [
401
- " harry" ,
402
- " ron" ,
403
- " hermione" ,
404
- " rubius" ,
405
- " albus" ,
406
- " severus" ,
407
- " luna" ,
408
- ]
409
- keys = [1 , 2 , 3 , 4 , 5 , 6 , 7 ]
410
- df1 = pd.DataFrame({" keys" : keys, " first_names" : first_names})
411
- df1
412
-
413
- surnames = [
414
- " hadrid" ,
415
- " malfoy" ,
416
- " lovegood" ,
417
- " dumbledore" ,
418
- " grindelwald" ,
419
- " granger" ,
420
- " weasly" ,
421
- " riddle" ,
422
- " longbottom" ,
423
- " snape" ,
424
- ]
425
- keys = [random.randint(1 , 7 ) for x in range (0 , 10 )]
426
- random_names = pd.DataFrame({" surnames" : surnames, " keys" : keys})
427
-
428
- random_names
429
-
430
- random_names.merge(df1, on = " keys" , how = " left" )
431
415
432
416
Adding a row
433
417
~~~~~~~~~~~~
0 commit comments