11: Associative Arrays in Python (1 of 3)

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.

    11: Associative Arrays in Python (1 of 3)

    Our next trick is to represent associative arrays (review section 7.1 if you need to) in Python. To do so, we will use another package, which goes by the adorable name “Pandas”:

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

    import pandas as pd

    This code should go at the top of your first notebook cell, right under your “import numpy as np” line. The two go hand in hand.

    By the way, just as there were other choices besides NumPy ndarrays to represent ordinary arrays, there are other choices in Python for associative arrays. The native Python dict (“dictionary”) is an obvious candidate. Because this won’t work well when the data gets huge, however, and because using Pandas now will set up our usage of tables nicely in the next few chapters, we’re going to use the Pandas Series data type for our associative arrays.


    This page titled 11: Associative Arrays in Python (1 of 3) was last modified on Sun, 18 Sep 2022 02:06:03 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.