12.5: Concatenating and Combining

The Crystal Ball - Instruction Manual I: Introduction to Data Science · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    From LibreTexts, under CC BY-SA 4.0, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    12.5: Concatenating and Combining

    Finally, it is sometimes convenient to be able to combine two or more Serieses into a single one. But there’s a catch. Remember that in order for a Series to “work properly,” its keys must be unique. Combining two Series which share at least one of the same keys is a recipe for disaster!

    The syntax for doing so, when the coast is clear, uses the .append() method:

    Code \(\PageIndex{1}\) (Python):

    crazy_example = salaries.append(slayers)

    print(crazy_example)

    | Michael 113.0

    | Dwight 68.0

    | Pam 67.0

    | Jim 100.2

    | Ryan 68.0

    | Xander 72.0

    | Willow 200.0

    | Rubert 150.0

    | Buffy 120.0

    | dtype: float64

    Nothing untoward happened here because The Office and Buffy don’t have any overlapping character names. Note that the values all got converted to float (instead of int), to enforce homogeneity. Note also that salaries itself did not change as a result of this .append() call; instead, a new Series was returned that contains all the items.


    This page titled 12.5: Concatenating and Combining was last modified on Sun, 18 Sep 2022 02:06:14 GMT and is shared under a CC BY-SA 4.0 license and was authored, remixed, and/or curated by Stephen Davies (allthemath.org) via source content that was edited to the style and standards of the LibreTexts platform.