Home > Mobile >  How to delete multiple rows in data frame at panda in python?
How to delete multiple rows in data frame at panda in python?

Time:09-06

I am using pandas to make a dataframe. I want to delete 12 initial rows by drop function. every resources website says that you should use drop to delete the rows unfortunately it doesn't work. I don't know why. the error says that 'list' object has no attribute 'drop' could you do me a favor and find it what should I do?

url=Exp01.html
url=str(url)
df = pd.read_html(url)
df = df.drop(index=['1','12'],axis=0,inplace=True)
print(df)

CodePudding user response:

Pandas read_html returns a list of dataframes. So df is a list on your example. First, take a look at what the list holds. If it's just one table (dataframe), you can change it to:

df = pd.read_html(url)[0]

CodePudding user response:

You can slice the rows out:

df = df.loc[11:]
df

loc in general is configured this way:

df.loc[x:y]

where x is the starting index and y is the ending index. [11:] gives starting index as 11 and no ending index

  • Related