Lesson 3: Summary functions and maps
    1 / 11

    Lesson 3 of 6 · about 20 minutes

    Summary functions and maps

    Summary functions

    pandas can sum up a whole column in a single call. describe() gives the main statistics at once:

    import pandas as pd
    
    sales = pd.DataFrame({
        "fruit": ["apple", "banana", "apple", "cherry", "banana", "apple"],
        "boxes": [12, 7, 9, 4, 10, 15],
        "price": [2.5, 1.2, 2.5, 6.0, 1.2, 2.4],
    })
    print(sales["boxes"].describe())

    The output:

    count     6.000000
    mean      9.500000
    std       3.834058
    min       4.000000
    25%       7.500000
    50%       9.500000
    75%      11.500000
    max      15.000000
    Name: boxes, dtype: float64

    count is how many values there are, mean the average, std how spread out they are, and the rest are the smallest value, the quartiles and the largest value.

    You can also ask for each one on its own:

    import pandas as pd
    
    boxes = pd.Series([12, 7, 9, 4, 10, 15])
    print(boxes.sum(), boxes.mean(), boxes.max(), boxes.min())
    print(boxes.median())

    The output:

    57 9.5 15 4
    9.5