to_pandas() -> to_df() adding additional columns functionality lost #203
-
In the to_pandas() method of our EventDataset class, we have an events_dataset.to_pandas(
additional_columns={"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": lambda event: int(sp_dataset.metadata.teams[0].team_id),
"away_team_id": lambda event: int(sp_dataset.metadata.teams[1].team_id),
},
) However, with the to_pandas() method being deprecated, I wanted to start replacing them to the to_df() method. However, this method does not seem to offer the same functionality to add additional_columns. How should we go about this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
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 |
Beta Was this translation helpful? Give feedback.
Would this work for you? https://kloppy.pysport.org/examples/event_data/#Use-metadata-when-transforming-to-pandas-dataframe
I didn't really know what
sp_dataset
is. You can also useevent.dataset
to refer to the dataset the event is pa…