High scorers
For the following exercises, we'll read nba_data.csv
CSV file, that contains data of NBA Players (original can be found here).
Your task: Get a list of all the players making more points than the double of the mean. That list should include just players name and points.
Test Cases
test high scorers - Run Test
def test_high_scorers():
assert high_scorers.shape == (45,2) and high_scorers.iloc[37,1] == 18.3
Solution 1
import numpy as np
import pandas as pd
df = pd.read_csv('nba_data.csv')
high_scorers = df.loc[df['Points'] > 2 * df['Points'].mean(), ['Player', 'Points']]
Files associated with this lesson:
nba_data.csv
Rk | Player | Position | Age | Mp | Fg | Fga | Fg% | 3P | 3Pa | 3P% | 2P | 2Pa | 2P% | Efg% | Ft | Fta | Ft% | Orb | Drb | Trb | Ast | Stl | Blk | Tov | Pf | Points | Team | Gp | Mpg | Orpm | Drpm | Rpm | Wins_Rpm | Pie | Pace | W | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1 | Russell Westbrook | PG | 28 | 34.6 | 10.2 | 24.0 | 0.425 | 2.5 | 7.2 | 0.343 | 7.7 | 16.8 | 0.459 | 0.476 | 8.8 | 10.4 | 0.845 | 1.7 | 9.0 | 10.7 | 10.4 | 1.6 | 0.4 | 5.4 | 2.3 | 31.6 | OKC | 81 | 34.6 | 6.74 | -0.47 | 6.27 | 17.34 | 23.0 | 102.31 | 46 |
1 | 2 | James Harden | PG | 27 | 36.4 | 8.3 | 18.9 | 0.440 | 3.2 | 9.3 | 0.347 | 5.1 | 9.6 | 0.530 | 0.525 | 9.2 | 10.9 | 0.847 | 1.2 | 7.0 | 8.1 | 11.2 | 1.5 | 0.5 | 5.7 | 2.7 | 29.1 | HOU | 81 | 36.4 | 6.38 | -1.57 | 4.81 | 15.54 | 19.0 | 102.98 | 54 |
2 | 3 | Isaiah Thomas | PG | 27 | 33.8 | 9.0 | 19.4 | 0.463 | 3.2 | 8.5 | 0.379 | 5.8 | 10.9 | 0.528 | 0.546 | 7.8 | 8.5 | 0.909 | 0.6 | 2.1 | 2.7 | 5.9 | 0.9 | 0.2 | 2.8 | 2.2 | 28.9 | BOS | 76 | 33.8 | 5.72 | -3.89 | 1.83 | 8.19 | 16.1 | 99.84 | 51 |
3 | 4 | Anthony Davis | C | 23 | 36.1 | 10.3 | 20.3 | 0.505 | 0.5 | 1.8 | 0.299 | 9.7 | 18.6 | 0.524 | 0.518 | 6.9 | 8.6 | 0.802 | 2.3 | 9.5 | 11.8 | 2.1 | 1.3 | 2.2 | 2.4 | 2.2 | 28.0 | NO | 75 | 36.1 | 0.45 | 3.90 | 4.35 | 12.81 | 19.2 | 100.19 | 31 |
4 | 5 | DeMar DeRozan | SG | 27 | 35.4 | 9.7 | 20.9 | 0.467 | 0.4 | 1.7 | 0.266 | 9.3 | 19.2 | 0.484 | 0.477 | 7.4 | 8.7 | 0.842 | 0.9 | 4.3 | 5.2 | 3.9 | 1.1 | 0.2 | 2.4 | 1.8 | 27.3 | TOR | 74 | 35.4 | 2.21 | -2.04 | 0.17 | 5.46 | 15.5 | 97.69 | 47 |
5 | 6 | DeMarcus Cousins | C | 26 | 34.2 | 9.0 | 19.9 | 0.452 | 1.8 | 5.0 | 0.361 | 7.2 | 14.8 | 0.483 | 0.498 | 7.2 | 9.3 | 0.772 | 2.1 | 8.9 | 11.0 | 4.6 | 1.4 | 1.3 | 3.7 | 3.9 | 27.0 | NO/SAC | 72 | 34.2 | 3.56 | 0.64 | 4.20 | 11.26 | 17.8 | 97.11 | 30 |
6 | 7 | Damian Lillard | PG | 26 | 35.9 | 8.8 | 19.8 | 0.444 | 2.9 | 7.7 | 0.370 | 6.0 | 12.1 | 0.492 | 0.516 | 6.5 | 7.3 | 0.895 | 0.6 | 4.3 | 4.9 | 5.9 | 0.9 | 0.3 | 2.6 | 2.0 | 27.0 | POR | 75 | 35.9 | 4.63 | -1.49 | 3.14 | 10.72 | 15.9 | 99.68 | 38 |
7 | 8 | LeBron James | SF | 32 | 37.8 | 9.9 | 18.2 | 0.548 | 1.7 | 4.6 | 0.363 | 8.3 | 13.5 | 0.611 | 0.594 | 4.8 | 7.2 | 0.674 | 1.3 | 7.3 | 8.6 | 8.7 | 1.2 | 0.6 | 4.1 | 1.8 | 26.4 | CLE | 74 | 37.8 | 6.49 | 1.93 | 8.42 | 20.43 | 18.3 | 98.38 | 51 |
8 | 9 | Kawhi Leonard | SF | 25 | 33.4 | 8.6 | 17.7 | 0.485 | 2.0 | 5.2 | 0.380 | 6.6 | 12.5 | 0.529 | 0.541 | 6.3 | 7.2 | 0.880 | 1.1 | 4.7 | 5.8 | 3.5 | 1.8 | 0.7 | 2.1 | 1.6 | 25.5 | SA | 74 | 33.4 | 5.83 | 1.25 | 7.08 | 15.53 | 17.4 | 95.79 | 54 |
9 | 10 | Stephen Curry | PG | 28 | 33.4 | 8.5 | 18.3 | 0.468 | 4.1 | 10.0 | 0.411 | 4.4 | 8.3 | 0.537 | 0.580 | 4.1 | 4.6 | 0.898 | 0.8 | 3.7 | 4.5 | 6.6 | 1.8 | 0.2 | 3.0 | 2.3 | 25.3 | GS | 79 | 33.4 | 7.27 | 0.14 | 7.41 | 18.80 | 15.1 | 105.08 | 65 |