170k views
5 votes
Descriptive statistics are important in sports. Data often involves a large number of measurements and players.

The NBA2019 dataset was taken from nbastuffer and includes information on several players such as team name, age, turnover percentage, and points per game.

Write a program to find the sample standard deviation, rounded to two decimal places, for all players on the list in a chosen column.

Ex: If the input is:

PointsPerGame
Then the output is:

The standard deviation for PointsPerGame is: 2.77
import pandas as pd
# Also import the scipy.stats module.

NBA2019_df = '''Type your code here to load the csv file NBA2019.csv.'''

# Input desired column. Ex: AGE, 2P%, or PointsPerGame.
chosen_column = '''Complete input code here.'''

# Create subset of NBA2019_df based on input.
NBA2019_df_column = '''Type your code here to subset NBA2019_df based on the chosen column.'''

# Find standard deviation and round to two decimal places.
sample_s = st.tstd(NBA2019_df_column)
sample_s_rounded = round(2, sample_s) #The student has incorrectly used the round() function.

# Output
print('The standard deviation for', '''Finish code for output here''')

User Bleater
by
8.0k points

1 Answer

4 votes

The Python program utilizes Pandas and SciPy to calculate the sample standard deviation for a chosen column in the NBA2019 dataset, providing a rounded result.

Below is the corrected and completed Python program:

```python

import pandas as pd

import scipy.stats as st

# Load the NBA2019 dataset from the CSV file

NBA2019_df = pd.read_csv('NBA2019.csv')

# Input desired column. Ex: AGE, 2P%, or PointsPerGame.

chosen_column = input('Enter the column name: ')

# Create a subset of NBA2019_df based on the chosen column.

NBA2019_df_column = NBA2019_df[chosen_column]

# Find standard deviation and round to two decimal places.

sample_s = st.tstd(NBA2019_df_column)

sample_s_rounded = round(sample_s, 2)

# Output

print(f'The standard deviation for {chosen_column} is: {sample_s_rounded}')

```

This program prompts the user to enter the desired column name, extracts the corresponding column from the NBA2019 dataset, calculates the sample standard deviation using `scipy.stats.tstd()`, and then prints the result rounded to two decimal places.

User Adam Prescott
by
7.8k points