Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Data Dictionaries in Python
#14
(Nov-25-2019, 10:51 AM)perfringo Wrote: You should modify filter provided by Dead_EyE according to your needs.

Thank you for your reply.

So Dead_EyE's code can be used to filter down the records in a data dictionary?

How can I apply this to my code below?

Is it possible to sum a value like 'Win' or would I have to add all win rows to list to do this?

premier = {} 

print()

# 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))
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
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