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
question from:
https://stackoverflow.com/questions/65660874/how-do-i-delete-a-list-of-rows-from-a-dataframe-in-pandas 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…