# 1.7 - Pandas Series

Last updated: February 21st, 2019

# Pandas Series - Exercises¶

In [1]:
import numpy as np
import pandas as pd

# This will help the formatting in the notebook, it's not important:
pd.options.display.float_format = '{:20,.2f}'.format


### Exercise 1¶

Using Pandas, create a Series with numbers from 10 to 15, and float type.

In [ ]:
# your code goes here

In [ ]:
series = pd.Series(data=np.arange(10, 16),
dtype=np.float64)
series


### Exercise 2¶

Add indexes from A to F to the previous series.

In [ ]:
# your code goes here

In [ ]:
series.index = ['A', 'B', 'C', 'D', 'E', 'F']

series


### Exercise 3¶

Add a new element to the series: G: 20.0.

In [ ]:
# your code goes here

In [ ]:
series['G'] = 20.0

series


### Exercise 4¶

Remove the first element from the series.

In [ ]:
# your code goes here

In [ ]:
series.drop('A', inplace=True) # also, del series['A']

series


### Exercise 5¶

Get the value at D index.

In [ ]:
# your code goes here

In [ ]:
series['D']


### Exercise 6¶

Get the values from B to E indexes.

In [ ]:
# your code goes here

In [ ]:
series['B':'E']


### Exercise 7¶

Get all the values higher than 12.

In [ ]:
# your code goes here

In [ ]:
series[series > 12.0]


### Exercise 8¶

Get the mean of all the series elements.

In [ ]:
# your code goes here

In [ ]:
series.mean()


### Exercise 9¶

Add 10 to the values higher than 14.

In [ ]:
# your code goes here

In [ ]:
series[series > 14.0] += 10

series


### Exercise 10¶

Double series elements lower than 14.

In [ ]:
# your code goes here

In [ ]:
series[series < 14.0] = 2 * series[series < 14.0]

series


For the following exercises, we'll read the csv file located in data/salaries.csv, that contains salaries of NBA Players (original can be found here).

We haven't dug into reading CSV files yet (there's a special lesson about that later), so we've already included the line that reads the salaries into a series.

In [3]:
salaries = pd.read_csv('data/salaries.csv', squeeze=True, index_col=0)


Out[3]:
Salary
Player
Stephen Curry 34,682,550.00
LeBron James 33,285,709.00
Paul Millsap 31,269,231.00
Gordon Hayward 29,727,900.00
Blake Griffin 29,512,900.00

### Exercise 11¶

Using Pandas, create a Series with numbers from 10 to 15, and float type.

How many players does the series salaries have?

In [ ]:
# your code goes here

In [7]:
salaries.size

Out[7]:
573

### Exercise 12¶

What are the highest and lowest salaries on the league?

In [4]:
# your code goes here

In [5]:
# Highest:
salaries.max()

Out[5]:
34682550.0
In [6]:
# Lowest:
salaries.min()

Out[6]:
17224.0

### Exercise 13¶

Show us LeBron James's salary (make sure you don't make a typo with his name, you'll get a KeyError otherwise):

In [9]:
# your code goes here

In [10]:
salaries.loc['LeBron James']

Out[10]:
33285709.0

### Exercise 14¶

Show us the first 10 players in the series:

In [ ]:
# your code goes here

In [ ]:


In [ ]:


In [ ]:


In [ ]: