0

I'm using selenium to scrape dynamic data from a trading website. I've scraped the whole table and add it to a data frame. Now, I want to delete the first row/column from my data frame and insert it into MySQL. But, I'm unable to delete that row/column.

enter image description here

Please help me to delete either the first row or column. I've tried but I can't able to do this :

df = df.iloc[: , 1:]

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_11560/1465043235.py in <module>
----> 1 df = df.iloc[: , 1:]

AttributeError: 'list' object has no attribute 'iloc'

1 Answers1

1

.read_html() returns a list of dataframes. You call the specific dataframes by the index position (Ie: like you did with df[1]. So you need to use .iloc on the dataframe in your list of dataframes, on index position 1.

df = df[1].iloc[: , 1:]
chitown88
  • 27,527
  • 4
  • 30
  • 59
  • but this gives me an error that : AttributeError: 'list' object has no attribute 'iloc' – Kashif Hussain Sep 07 '21 at 09:01
  • thanks, it is working...please tell me how to remove the 1st line containing column names like "ask", "bid" etc – Kashif Hussain Sep 07 '21 at 09:16
  • you can't remove the columns from a dataframe (then it's not a dataframe). what are you trying to do exactly? – chitown88 Sep 07 '21 at 09:24
  • I wanna insert that data into MySQL and don't know how to do it. I have made a database and a table and made a connection and now I don't know how many columns should i made in my table and what will be the query? – Kashif Hussain Sep 07 '21 at 09:34
  • [https://stackoverflow.com/questions/16476413/how-to-insert-pandas-dataframe-via-mysqldb-into-database](https://stackoverflow.com/questions/16476413/how-to-insert-pandas-dataframe-via-mysqldb-into-database) – chitown88 Sep 07 '21 at 09:36
  • i've used the following code and getting error please check this from sqlalchemy import create_engine engine = create_engine('mysql+pymysql://root:@localhost/mql5') con = engine.raw_connection() df.to_sql('forex', con = con, if_exists='replace') and Error is : DatabaseError: Execution failed on sql 'SELECT name FROM sqlite_master WHERE type='table' AND name=?;': not all arguments converted during string formatting – Kashif Hussain Sep 07 '21 at 11:59