Python Forum
drop row index , how to show new df
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
drop row index , how to show new df
#1
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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  PIL Image im.show() no show! Pedroski55 2 928 Sep-12-2022, 10:19 PM
Last Post: Pedroski55
  PIL Image im.show() no show! Pedroski55 6 4,740 Feb-08-2022, 06:32 AM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020