Python Program - Please include #Comments to explain each line if possible. Spor
ID: 3808246 • Letter: P
Question
Python Program - Please include #Comments to explain each line if possible.
Sports data is an area of keen interest both to fans and coaches alike. In this lab, we will be using a file from http://www.databasebasketball.com/stats_download.htm. Download the file and pick out the player_regular_season.csv file which has over 20,000 rows of basketball data from 1946 to 2009. The data in the file is described at http://www.databasebasketball.com/about/aboutstats.htm. Who was the best NBA basketball player? The NBA is North America’s professional men’s basketball league. You are going to write a program to find the best players in NBA history using Python3.4. Using the csv file provided with the lab instruction (The links above). Calculate the efficiency for each player, using the csv file provided with the lab. NBA player’s performance is evaluated using the following efficiency formula. Efficiency = ( ( pts + reb + asts + stl + blk ) - ( ( fga – fgm ) + ( fta – ftm ) + turnover ) ) / gp
1. Find the top 50 players with the best efficiency results and Display those 50 from best to worst.
2. Find and display the Player who played the most minutes
3. Find and display the player who play the most games
4. Find and display the Player who scored the most points.
5. Find and display the Player who made the most free throws.
Explanation / Answer
bb = pd.read_csv('player_regular_season.csv')
bb['Efficiency'] = ( ( bb.pts + bb.reb + bb.asts + bb.stl + bb.blk ) - ( ( bb.fga - bb.fgm ) + ( bb.fta - bb.ftm ) + bb.turnover ) ) / bb.gp
#1.
bb.sort_values(by='Efficiency', ascending=False).head(50)[['firstname','lastname']]
#2.
bb.sort_values(by='minutes', ascending=False).head(1)[['firstname','lastname']]
#3.
bb.sort_values(by='gp', ascending=False).head(1)[['firstname','lastname']]
#4.
bb.sort_values(by='pts', ascending=False).head(1)[['firstname','lastname']]
#5.
bb.sort_values(by='ftm', ascending=False).head(1)[['firstname','lastname']]
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.