What's a CodeballFrame?
CodeballFrames are subclasses of Pandas DataFrames. They have all the methods of a
standard DataFrame, but have additional methods and attributes that make it easier
to work, filter, and handle data from the game. The base class is
the main CodeballFrame classes are
EventsFrame. An important
aspect of CodeballFrame, as it is the case for DataFrames, is that methods can be chained.
Attributes / properties
All CodeballFrame have 3 attributes:
- records: this holds the records from the datasets created by Kloppy when reading in the data. This attribute is not passed to the result of any action that modifies the data frame.
- metadata: this holds the metadata from the datasets created by Kloppy when reading in the data. This attribute is preserved when filtering or modifying the data frame. However is lost if the result is a series.
- data_type: this indicates what type of data the data frame holds. For example
A CodeballFrame that holds tracking data.
TrackingFrame.team(team_id)will return a TrackingFrame only containing the columns that have data for team with id team_id.
TrackingFrame.dimension('x')will return a TrackingFrame only containing the columns with data on the x axis.
TrackingFrame.players('field')will return a TrackingFrame only containing the columns with data for the field players (excluding goalkeeper).
TrackingFrame.players()will return a TrackingFrame containing the data for all players but drop all the other columns.
TrackingFrame.phase(defending_team=team_id)will return a Series with True on the frames the team with id
team_idwas defending and False otherwise.
TrackingFrame.stretched(50)will return a Series with True on the frames the stretched of the values in the columns of the TrackingFrame is higher than the threshold.
Since all these methods can be chained, is you want to get the x coordinates of field players
for team with id
team_id, you can do:
A CodeballFrame that holds event data.
- type(): This allows to filter by the
EventsFrame.type('PASS')will return a EventsFrame only containing the rows that correspond to
- result(): This allows to filter by the
EventsFrame.result('COMPLETE')will return a EventsFrame only containing the events with result
- into(), starts_inside(), starts_outside(), ends_inside(),
ends_outside(): are all similar. They take one or more
Area(see the tactical section) and filter events depending on whether they start, end, etc in that
Zones. Zones will be able to be defined by the user, or use any of the ones defined in the package (link to Tactical) module to be added later to the documentation.
These methods can also be chained, so if you wanted to filter by completed passes into the opponents box you can do: