Generation

generate functionTue, 21 Mar 2023

There is a "grass" Pandas dataframe: pid Name Class 1 Class 2 HP Attack Defense Sp. Atk Sp. Def Speed Legendary 0 1 Bulbasaur Grass Poison 45 49 49 65 65 45 False 1 2 Ivysaur Grass Poison 60 62 63 80 80 60 False 2 3 Venusaur Grass Poison 80 82 83 100 100 80 False 3 4 Mega Venusaur Grass Poison 80 100 123 122 120 80 False 48 49 Oddish Grass Poison 45 50 55 75 65 30 False Write a function that will search for 'Rock' values in the Class 1 and Class 2 columns. And if it finds such values it will delete these rows.

def rock(dataframe): for i in range(0, len(dataframe)): if(dataframe['Class 1'][i] == 'Rock' or dataframe['Class 2'][i] == 'Rock'): dataframe.drop(i, inplace = True) return dataframe rock(df)

Questions about programming?Chat with your personal AI assistant