Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Data Dictionaries in Python
#10
So I used this appraoch below:

How can I get the average points and pick teams that have finished first?

Sample data at the very bottom

# Purpose: Inputing data from a csv file
# Example of: File input from a csv file, using a dictionary

print("This program loads all historic premier league data")

# start with an empty dictionary
# dictionary keys will be the (Pos, Club)
premier = {}

print()
print("Historic premier league")
# open the file
with open(r"Historic_PL.csv") as data_file:
# read in the first line containing the headers
headers = data_file.readline()

# for each other line in the file
for line in data_file:
# split each line into components (remove white space from ends of line)
Pos,Club,Seasons,Pld,Win,Draw,Loss,GF,GA,GD,Pts,First,Second,Third,Fourth,Relegated,Best = line.strip().split(",")

# insert the data into the dictionary
premier[(int(Pos), Club)] = (int(Seasons),int(Pld),int(Win),int(Draw),int(Loss),int(GF),int(GA),int(GD),int(Pts),int(First),int(Second),int(Third),int(Fourth),int(Relegated),int(Best))

print(f"Number of values: {len(premier)}")



################################################################
Pos,Club,Seasons,Pld,Win,Draw,Loss,GF,GA,GD,Pts,First,Second,Third,Fourth,Relegated,Best
1,Manchester United,27,1038,648,224,166,1989,929,1060,2168,13,6,3,1,0,1
2,Arsenal,27,1038,565,260,213,1845,1013,832,1955,3,6,5,7,0,1
3,Chelsea,27,1038,558,257,223,1770,1002,768,1931,5,4,5,2,0,1
4,Liverpool,27,1038,529,262,247,1774,1046,728,1849,0,4,5,7,0,2
5,Tottenham Hotspur,27,1038,446,257,335,1547,1306,241,1595,0,1,2,3,0,2
6,Everton,27,1038,377,296,365,1357,1311,46,1427,0,0,0,1,0,4
7,Manchester City,22,848,391,196,261,1374,975,399,1369,4,2,2,1,2,1
Reply


Messages In This Thread
Data Dictionaries in Python - by mrsenorchuck - Nov-24-2019, 01:31 AM
RE: Data Dictionaries in Python - by Larz60+ - Nov-24-2019, 03:35 AM
RE: Data Dictionaries in Python - by mrsenorchuck - Nov-24-2019, 10:12 AM
RE: Data Dictionaries in Python - by DeaD_EyE - Nov-24-2019, 10:32 AM
RE: Data Dictionaries in Python - by mrsenorchuck - Nov-24-2019, 10:50 AM
RE: Data Dictionaries in Python - by snippsat - Nov-24-2019, 02:07 PM
RE: Data Dictionaries in Python - by mrsenorchuck - Nov-24-2019, 02:11 PM
RE: Data Dictionaries in Python - by perfringo - Nov-24-2019, 02:49 PM
RE: Data Dictionaries in Python - by mrsenorchuck - Nov-24-2019, 05:04 PM
RE: Data Dictionaries in Python - by mrsenorchuck - Nov-24-2019, 08:02 PM
RE: Data Dictionaries in Python - by DeaD_EyE - Nov-25-2019, 08:26 AM
RE: Data Dictionaries in Python - by mrsenorchuck - Nov-25-2019, 09:36 AM
RE: Data Dictionaries in Python - by mrsenorchuck - Nov-25-2019, 09:29 PM
RE: Data Dictionaries in Python - by perfringo - Nov-25-2019, 10:51 AM
RE: Data Dictionaries in Python - by mrsenorchuck - Nov-25-2019, 02:58 PM
RE: Data Dictionaries in Python - by DeaD_EyE - Nov-25-2019, 04:07 PM
RE: Data Dictionaries in Python - by mrsenorchuck - Nov-25-2019, 04:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I save Python dictionaries in Matlab? jlostinco 1 2,862 Jul-04-2019, 11:35 PM
Last Post: scidam
  creating an 'adress book' in python using dictionaries? apollo 6 14,953 May-06-2019, 12:03 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020