Created
December 15, 2019 01:18
-
-
Save senthilsweb/2b860519fe703114322bd86dd02af98a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ----------------------------------------------------- | |
# Query sqlite using sqlalchemy | |
# dependencies: Pandas & sqlalchemy | |
# | |
# ----------------------------------------------------- | |
# {Modification Log} | |
# ----------------------------------------------------- | |
# Author: Senthilnathan | |
# Maintainer: {maintainer} | |
# Created At: 12/14/2019 | |
# Last Modified: 12/14/2019 | |
# Status: production | |
# ----------------------------------------------------- | |
import pandas as pd | |
from sqlalchemy import create_engine | |
import datetime as dt | |
# variables (Start) | |
dbname='meetup' | |
tname='members' | |
encoding='ISO-8859-1' | |
start = dt.datetime.now() | |
# variables (End) | |
try: | |
csv_database = create_engine('sqlite:///{}.db'.format(dbname)) | |
df = pd.read_sql_query('select * from {} ORDER BY random() limit 5'.format(tname), csv_database) | |
print(df) | |
except Exception as e: | |
print('Exception while querying {} - [{}]'.format(dbname,str(e))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment