Lesson 6 of 23
โฎPrev Nextโฏ

PY-401 ยท pandas basics

pandas Series

โฑ 9 min ๐Ÿ Real Python 3 ๐ŸŽฌ Animated

6of 23

Your note

My notes for this lesson

Select any text in the lesson to highlight it or add a note. Saved in this browser.

    No highlights yet. Select a sentence in the lesson, then pick a colour or add a note.

    All my bookmarks and notes

    Reading settings

    For every lesson, saved in this browser.

    Text size
    Line spacing
    Font

    With IaaS you rent the virtual machine. Microsoft looks after the building, power and hardware; you patch the operating system.

    โšก The 30-second answer

    A pandas Series is a single column of values where every value has a label, called the index. It works like a NumPy array, so sales.mean() and sales > 100 run on every value, but you can also read a value by its label, such as sales["Tue"]. Every column of a pandas table is a Series.

    • Create a Series with an index
    • Read a value by its label
    • Do maths and filter like an array

    Try it

    Watch it come alive, run it yourself, then prove it. Real Python, right on this page.

    Watch Python run the example. Every variable is a jar; watch the values change and the output appear.

    pandas Series, running
    1. import pandas as pd
    2. sales = pd.Series([120, 340, 95, 410], index=["Mon", "Tue", "Wed", "Thu"])
    3. print(sales)
    4. print(sales["Tue"])
    5. print(sales.mean())
    6. print(sales[sales > 100].index.tolist())
    Press โ–ถ to watch Python run this, one line at a time.
    1. The problemA cafรฉ owner writes daily sales on a whiteboard: Mon 120, Tue 340, Wed 95. A NumPy array would keep the numbers but lose the day names. A Series keeps both.
    2. The Python ideaimport pandas as pdA pandas Series is a single column of values where every value has a label, called the index.
    3. In real lifeA stock app keeps a share price as a Series indexed by date, so "the price on 3 March" is prices["2026-03-03"] and a 7-day average is one call.

    Start with a question

    A cafรฉ owner writes daily sales on a whiteboard: Mon 120, Tue 340, Wed 95. A NumPy array would keep the numbers but lose the day names. A Series keeps both.

    Real data has names attached: dates, products, customers. A Series keeps the name next to the number, so results stay readable.

    Explain it like I'm 10

    A Series is a row of lockers. Each locker has a name tag on the door (the index) and something inside (the value). You can open a locker by its name instead of counting.

    The technical explanation

    Start with import pandas as pd. pandas is built on NumPy, so the maths you learned in module 1 works the same way.

    pd.Series([120, 340], index=["Mon", "Tue"]) makes a Series. Without index=, the labels are 0, 1, 2 and so on.

    Printing a Series shows the labels on the left, the values on the right and the dtype at the bottom.

    sales.mean(), sales * 1.1 and sales[sales > 100] behave like a NumPy array, and the labels travel with the values.

    Syntax

    import pandas as pd
    s = pd.Series(values, index=labels)
    s["label"]       # by label
    s.iloc[0]        # by position
    s[s > 100]       # filter

    โ–ถ Run the example ๐ŸŽฌ Watch it come alive

    Real-world scenario

    A stock app keeps a share price as a Series indexed by date, so "the price on 3 March" is prices["2026-03-03"] and a 7-day average is one call.

    Ready for more?The full lesson adds the technical explanation, interview questions and quick revision.

    Test yourself

    5 questions. Get 4 right and this lesson is marked complete.

    1. 1. What does a Series add on top of a NumPy array?
    2. 2. s = pd.Series([5, 8], index=["a", "b"]). What is s["b"]?
    3. 3. How do you read the first value by position?
    4. 4. What are the labels if you leave out index=?
    5. 5. How does almost everyone import pandas?

    Questions people ask

    What is the difference between a pandas Series and a DataFrame?

    A Series is one column of values with an index. A DataFrame is a table of several Series that share the same index, one Series per column.

    What is the difference between a Series and a Python dictionary?

    Both map labels to values, but a Series keeps its labels in order, holds one type of value and supports vectorised maths and filtering like s > 100, which a dictionary does not.

    Interview questions

    How this topic comes up in Python interviews. Answer out loud first, then open the model answer.

    beginner What is the difference between a pandas Series and a DataFrame?

    A Series is one column of values with an index. A DataFrame is a table of several Series that share the same index, one Series per column.

    beginner What is the difference between a Series and a Python dictionary?

    Both map labels to values, but a Series keeps its labels in order, holds one type of value and supports vectorised maths and filtering like s > 100, which a dictionary does not.

    intermediate What does a Series add on top of a NumPy array?

    A label for every value. The index gives every value a label.

    intermediate s = pd.Series([5, 8], index=["a", "b"]). What is s["b"]?

    8. Square brackets with a label read that value.

    Quick revision

    Remember

    • Create a Series with an index
    • Read a value by its label
    • Do maths and filter like an array
    • sales[0] on a Series with text labels is confusing and now warns. Use sales["Mon"] for labels and sales.iloc[0] for positions.

    Syntax

    import pandas as pd
    s = pd.Series(values, index=labels)
    s["label"]       # by label
    s.iloc[0]        # by position
    s[s > 100]       # filter

    Official documentation