0

I have created a sqlite database in sqlalchemy and I have inserted data into it. Now I would like to get the total number of rows that was inserted.

I am trying to follow the example of this stack overflow question

Get the number of rows in table using SQLAlchemy

However, this involved creating a 'Congress' class and geoalchemy library, which I am not sure where they came from, or how they are related.

This is my code

import sqlalchemy
from sqlalchemy import create_engine
engine = sqlalchemy.create_engine("sqlite:///dbfile/CSSummaries.db")
pandasDataframeExample.to_sql('CS_table', engine, index = False, if_exists= 'append')

Now I would like to see how many rows have been added, and perhaps see a few samples from the database to make sure everything saved ok.

I would like to see that it has x many rows.

Bonus:

A easy to way to sample some of the data in the database.

Peter Force
  • 439
  • 1
  • 5
  • 13

1 Answers1

0

Could run it through a for loop:

import sqlalchemy
from sqlalchemy import create_engine
engine = sqlalchemy.create_engine("sqlite:///dbfile/CSSummaries.db")
for i in range(len(pandasDataframeExample)): 
    DataFrame.iloc[0].to_sql('CS_table', engine, index = False, if_exists= 'append')
    if i%10 == 0: 
        print('rows inserted: ' + str(i))
johnny1995
  • 123
  • 1
  • 10