1

So I have a huge structure in MATLAB containing every single player in the english premier league (688 of them). Inside the section on a single player there are more arrays containing various statistics (tackles, crosses, goals etc) for every single game played in the season.

So to clarify, I have a 688 length struct, containing around 40 elements. Each element is an array with 38 entries.

What data structure would you use to store this data? I've been reading about relational databases and think I should start learning about PostgreSQL.. I just wanted to ask on here what you would use?

2 Answers 2

1

You definitely could use an SQL database, but if you wanted to stick with strictly python, you could take advantage of Python's object oriented programming style. I would define an object class as so:

class Player:
    def __init__(self, optional_paramater1, opt_param2):
        #Stuff you want to happen when object is initialized

    def read_in_matlab_structure(self, matlab_info_as_text):
        self.tackles = #Wheverever you get this info from
        self.crosses = #...
        self.goals = #...

Then, when you make the object, you can access each of the values below a self defined name.

players = [] #This would be a list. Depending on your use, you could also
             #Use a dictionary that links name to the object
             #That way you can call up a person by name. 
             #eg. players["Babe Ruth"]
             #There are also sets in Python that might be applicable to
             #Your situation.
for entry in matlab_structure:
    temp_player = Player(name)
    temp_player.read_in_matlab_structure(entry)
    players.append(temp_player)
#then, when you want to access player information, 
#  lets say you want to see all the players who had more than 8 goals in a season:
for person in players:
    if person.goals >= 8:
        print(person.name)

Hope this gives you an idea. More info on Python data structures:

Python 3 Data Structures

Sign up to request clarification or add additional context in comments.

1 Comment

amazing! Thanks, this is perfect
1

In terms of built in data structures a dictionary sounds like your best bet. You can export it with the json module if that's necessary.

For an external databases, SQLite is probably your best choice. It requires a lot less setup than other SQL databases. As in you can just make a .db file and start sending data to it without any administrative work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.