Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is a Python question: # 2-3: Compute and display z-scores for Dallas Cowboy

ID: 3876231 • Letter: T

Question

This is a Python question:

# 2-3: Compute and display z-scores for Dallas Cowboys, Oakland Raiders, and Chicago Bears. (2 points)

# And then print out the team names of all outliers based on z-score.
# Read the textbook if you don't know how to determine outliers based on z-score.

#I tried to read csv file named "NFLTeamValue.csv" and transfer it to value.

import csv
data = []
with open ("NFLTeamValue.csv")as csv_file:
csv_reader=csv.reader(csv_file)
header = next(csv_reader)
for row in csv_reader:
Revenue = int(row[1])
Current_value = int(row[2])
data.append([row[0], Revenue, Current_value])
  
print(Revenue)

but the output said I cannot transfer '1,227' to an int value. I also tried to use float but still doesn't work.

Is anyone can help me to solve this problem?

Thanks!

Explanation / Answer

Your python code was correct, this is the correct way to read the csv file.

NFLTeamValue.csv

Team,Revenue ($ millions),Current Value ($ millions)
Arizona Cardinals,253,961
Atlanta Falcons,252,933
Baltimore Ravens,292,"1,227"
Buffalo Bills,256,870
Carolina Panthers,271,"1,057"
Chicago Bears,298,"1,252"
Cincinnati Bengals,250,924
Cleveland Browns,264,"1,005"
Dallas Cowboys,539,"2,300"
Denver Broncos,283,"1,161"
Detroit Lions,248,900
Green Bay Packers,282,"1,183"
Houston Texans,320,"1,450"

From the above NFLTeamValue.csv, carefully see the highlighted lines. The “current values” are in double quotes having the delimiter “,”. Therefore, the value cannot transfer.

You can remove it and use the .csv file. The below data is the sample one.

Team,Revenue ($ millions),Current Value ($ millions)

Arizona Cardinals,253,961

Atlanta Falcons,252,933

Baltimore Ravens,292,1227

Buffalo Bills,256,870

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote