# Python Pandas For Your Grandpa - 2.11 Challenge: Car Shopping

Setup After accidentally leaving an ice chest of fish and shrimp in your car for a week while you were on vacation, you’re now in the market for a new vehicle. Your insurance didn’t cover the loss, so you want to make sure you get a good deal on your new car. Given a Series of car asking_prices and another Series of car fair_prices, determine which cars for sale are a good deal.

# Python Pandas For Your Grandpa - 2.12 Challenge: Price Gouging

Setup You suspect your local grocery’s been price gouging the ground beef. So, you and some friends decide to track the price of ground beef every day for 10 days. You’ve compiled the data into a Series called beef_prices, whose index represents the day of each recording. Determine which day had the biggest price increase from the prior day. (Note that the index of beef_prices represents the day tracked, and it’s not in order.

# Python Pandas For Your Grandpa - 2.13 Challenge: Fair Teams

Setup You’re organizing a competitive rock-skipping league. 6 coaches and 20 players have signed up. Your job is to randomly and fairly determine the teams, assigning players to coaches. Keep in mind that some teams will have three players and some teams will have four players. Given a Series of coaches and a Series of players, create a Series of random coach-to-player mappings. The resulting Series should have coach names in its index and corresponding player names in its values.

# Python Pandas For Your Grandpa - 2.2 Series Basic Indexing

In this video, we’ll see how to use the index of a Series to access and modify its elements in meaningful ways. Suppose we have the following Series, x import numpy as np import pandas as pd x = pd.Series([5, 10, 15, 20, 25]) print(x) ## 0 5 ## 1 10 ## 2 15 ## 3 20 ## 4 25 ## dtype: int64 If you wanted to access the ith element of the Series, you might be inclined to use square-bracket indexing notation just like accessing elements from a python list or a NumPy array.

# Python Pandas For Your Grandpa - 2.3 Series Basic Operations

In this video, we’ll see how you can add two series together. And even though we’re only talking about addition, everything we discuss applies to other basic math operations like subtraction, multiplication, and division. Suppose you have the following series of integers, 1 2 3 4, and you add a scalar to it. import numpy as np import pandas as pd x = pd.Series([1, 2, 3, 4]) x + 1 ## 0 2 ## 1 3 ## 2 4 ## 3 5 ## dtype: int64 Just like in NumPy, Pandas uses broadcasting to add the scalar to each element of the Series.

# Python Pandas For Your Grandpa - 2.4 Series Boolean Indexing

In this section, we’ll see how to use boolean indexing to select values from a Series based on logical conditions. Just like NumPy arrays, you can subset a Pandas Series using a boolean index For example, if you have a Series of integers like this one called foo import numpy as np import pandas as pd foo = pd.Series([20, 50, 11, 45, 17, 31]) print(foo) ## 0 20 ## 1 50 ## 2 11 ## 3 45 ## 4 17 ## 5 31 ## dtype: int64 if you check foo < 20, you’ll get back a corresponding Series of boolean values.