Python Forum

Full Version: drop row index , how to show new df
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hi, i have data i downloaded from the internet so it is not in a structured table, there are rows i want to delete. using a regex, i am able to identify the rows but dropping them from the dataframe and displaying a new dataframe based on dropped rows is my challenge. the new df should display the data without these rows..

here is the code and a pic of data

for i in df.index:
    if any(re.findall(r'HOME ADVANTAGE|RATING|through games of', df.iloc[i,0] ) ):
        df.drop(df.iloc[i,0], inplace=False)
        print(df)
[Image: uc?id=1uLeosDrR7v2W1Z2Jw73FBu__6sy063X_]

i ended up placing the index row in a list and dropping the list. this worked. is there a better way?

rows=[]

for i in df.index:
    if any(re.findall(r'HOME ADVANTAGE|RATING|through games of', df.iloc[i,0] ) ):
        rows.append(i)

df = df.drop(rows)
print(df)