I am trying to understand what the following snippet of the code does, in particular the assign(home=1).rename part:
goal_model_data = pd.concat([epl[['HomeTeam','AwayTeam','HomeGoals']].assign(home=1).rename(
columns={'HomeTeam':'team', 'AwayTeam':'opponent','HomeGoals':'goals'}),
epl[['AwayTeam','HomeTeam','AwayGoals']].assign(home=0).rename(
columns={'AwayTeam':'team', 'HomeTeam':'opponent','AwayGoals':'goals'})])
This is taken from text
That deals with regression modelling in pandas. I don't exclude the possibilities of mistakes in the code snippets they provide. But when I run the code, it seems to function properly. But I don't actually understand the meaning of the above given code and how it functions.
Please help.
DataFrame.assign(**kwargs), it's like doingdict(home=1)(equivalent to{"home": 1}).df.assign(home=1)is equivalent todf.assign(**{"home": 1}).