Python Forum
Using pyodbc&pandas to load a Table data to df
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using pyodbc&pandas to load a Table data to df
#1
Greetings!
I'm connecting to a DB and can get all the tables from it. No errors
I wanted to find a table named "ToolHistory" and later some other tables and then use pandas DF and filter some rows from the table/tables.
Here is what I got so far:
conn = pyodbc.connect('DRIVER={SQL Server};SERVER=SomeServer.com,1433;DATABASE=QQS;UID=me;PWD=allgetlost')
cursor = conn.cursor()
for row in cursor.tables():
    print(f" >> {row.table_name}")
    sql_query = 'SELECT * FROM ToolHistory'
    df = pd.read_sql(sql_query, conn)
    # tb_one = row.table_name
    # if tb_one == 'ToolHistory' :
        # print('Found Table ->',tb_one)    
        #df = pd.read_sql_table('tb_one', conn)
        #df = pd.read_sql_table('tb_one', cursor)
I cannot pass the line after the
print(f" >> {row.table_name}")
Any help is appreciated.
Thank you.
Reply


Messages In This Thread
Using pyodbc&pandas to load a Table data to df - by tester_V - Sep-09-2023, 05:12 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Load data in Oracle muzokh 0 284 Mar-08-2024, 11:19 PM
Last Post: muzokh
  Better python library to create ER Diagram by using pandas data frames as tables klllmmm 0 1,209 Oct-19-2023, 01:01 PM
Last Post: klllmmm
  Trying to get counts/sum/percentages from pandas similar to pivot table cubangt 6 1,498 Oct-06-2023, 04:32 PM
Last Post: cubangt
  python pandas sql table with header mg24 3 2,026 Dec-08-2022, 08:31 PM
Last Post: Larz60+
  Load multiple Jason data in one Data Frame vijays3 6 1,608 Aug-12-2022, 05:17 PM
Last Post: vijays3
  panda table data kucingkembar 0 1,145 Mar-01-2022, 10:38 PM
Last Post: kucingkembar
  Sorting table data Blacktime2 1 1,366 Feb-26-2022, 07:05 PM
Last Post: ibreeden
  pyodbc gmerritt 8 2,970 Feb-21-2022, 07:21 PM
Last Post: gmerritt
  Move a particular row in pandas data frame to last row klllmmm 0 3,826 Dec-27-2021, 09:11 AM
Last Post: klllmmm
  Strategy on updating edits back to data table and object variables hammer 0 1,215 Dec-11-2021, 02:58 PM
Last Post: hammer

Forum Jump:

User Panel Messages

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