Skip to content

to_pandas() -> to_df() adding additional columns functionality lost #203

Closed Answered by koenvo
DriesDeprest asked this question in Q&A
Discussion options

You must be logged in to vote

Would this work for you? https://kloppy.pysport.org/examples/event_data/#Use-metadata-when-transforming-to-pandas-dataframe

events_dataset.to_df(
  "*",
  opponent_team_id=lambda event: int(
      sp_dataset.metadata.teams[1].team_id
      if event.team == sp_dataset.metadata.teams[0]
      else sp_dataset.metadata.teams[0].team_id
  ),
  home_team_id=int(sp_dataset.metadata.teams[0].team_id), # don't need to use lambda as the data is independent of `event`
  away_team_id=int(sp_dataset.metadata.teams[1].team_id) # don't need to use lambda as the data is independent of `event`
)

I didn't really know what sp_dataset is. You can also use event.dataset to refer to the dataset the event is pa…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@DriesDeprest
Comment options

Answer selected by DriesDeprest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #202 on July 05, 2023 09:17.