Skip to main content
Engineering LibreTexts

12.3: Copying Serieses

  • Page ID
    39280
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    The rules for copying (or not copying) Serieses are exactly the same as for NumPy arrays (see Section 9.4). If you merely assign one Series object to another variable, the two variables will be pointing to the same Series in memory, which means that changes to one will be reflected in the other. Calling the .copy() method, however, creates an entirely new Series in memory.

    Make sure you understand the following output to confirm your understanding of this:

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

    slayers = pd.Series([120, 72, 200], index=['Buffy','Xander','Willow'])

    anti_vamps = slayers

    good_guys = slayers.copy()

    anti_vamps['Rubert'] = 150

    print(slayers)

    | Buffy 120

    | Xander 72

    | Willow 200

    | Rubert 150

    | dtype: int64

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

    print(anti_vamps)

    | Buffy 120

    | Xander 72

    | Willow 200

    | Rubert 150

    | dtype: int64

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

    print(good_guys)

    | Buffy 120

    | Xander 72

    | Willow 200

    | dtype: int64

    (The numbers here are approximate IQs; don’t mean to be a hater.)


    This page titled 12.3: Copying Serieses 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; a detailed edit history is available upon request.