I want to append a string to a column which is a numpy.ndarray object.The following code is not working:
def filter_by_player(df, players, team):
filtered_df = df[df['player'].isin(players)]
filtered_df['league'] = filtered_df['league'].apply(lambda x: x + [team])
return filtered_df
the league column looks like this ['barca','real','sevilla']. I want to add to it but the code above is not working.
players = ['messi', 'benzema', 'busquets']
league_df
player | team
messi | ['barca']
lewandowski | ['dortmund', 'bayern', 'barca']
when i call the function filter_by_player(players, 'psg')
the new dataframe league_df should become this as messi is in the list of players:
player | team
messi | ['barca', 'psg']
leaguecolumn after filtering?psgto the list of players tohat you pass as parameter? and then filter the data by that list as well? Its unclear if you are performing 2 tasks (addition of team name and filtering ) or you are just filtering.