2

I have a list of football teams stored in a variable called big_teams. I have a dataset of all games played in a football league over many seasons. What I am trying to do is create two new dataframes, one with the big teams and one with the small teams. I am not sure where my flaw is because I am fairly new to coding and python in general.

big_teams = []
small_teams = []

    for team in different_teams:
        if n_games[team] > np.average(n_games):
            big_teams.append(team)
        elif n_games[team] < np.average(n_games):
            small_teams.append(team)

The code above works, and two new lists have been generated each with different teams.

my problem is with the code below, I had hoped that it would create two new dataframes, or more accurately dropped what i didn't want from the existing dataframe

big_df = pd.DataFrame(df)
small_df = pd.DataFrame(df)

    for team in df['HomeTeam']:
        if team in big_teams == True:
            df['HomeTeam'].drop(team)
        elif team in small_teams == True:
            df['HomeTeam'].drop(team)

Thanks in advance

1 Answer 1

2

You can do isin

df = df[~df['HomTeam'].isin(big_teams+ small_teams)]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.