Getting started
SQLite is a common SQL database engine. In this blog, I will go over how you can connect and query a SQLite database in Python.
Let’s import the necessary libraries for this example, and establish a connection to a database. We will be using the sqlite3 library and pandas.
import sqlite3
import pandas as pd
conn = sqlite3.connect('supermarket.db') # connect to a supermarket database
To execute SQL commands, we need to create a cursor object. Let’s use the cursor to create a table called shops which will contain basic information about our supermarket stores (shop ID, size, postcode) . The store sizes are small, medium and large.
cursor = conn.cursor() # create a cursor
cursor.execute("CREATE TABLE shops(shopid VARCHAR(100) PRIMARY KEY, Store_size VARCHAR(30), Postcode VARCHAR(8))")
So, cursor.execute() executes SQL commands.
We can insert data into the table using the INSERT command. If we do this, use conn.commit() to save the data to the table.
However, in this example, we have a pandas DataFrame called shops_df that we wish to insert into our SQL table called shops. It has the same columns as our shops table. If you’re more familiar with pandas than SQL like me, I will use pandas to clean data first. Only after this will I want to store the data in an SQL database.
The to_sql() function allows us to write records in a DataFrame to an SQL database.
shops_df.to_sql('shops', conn, if_exists='append', index=False) # write shops_df to shops table
Queries
The cursor behaves like an iterator object. We can use a for loop to retrieve all rows from a SELECT statement. To make it easier to query in future, I’ll create a query function.
def query(q):
try:
for row in cursor.execute(q):
print(row)
except Exception as e:
print("Something went wrong... ", e)
query('SELECT * FROM shops')
We can also save the results of a query by assigning it to a variable. The variable will be a list of tuples. A tuple for each row.
q="SELECT shopid, Postcode FROM shops"
query_results = cursor.execute(q).fetchall() # save results as a list of tuples
Storing results from a query like this can allow you to represent table data with graphs. For example, if you had a table called sales in your database which has the shop profits, you could plot trends in sales. I will illustrate this now.

Let’s query the minimum, mean and maximum yearly sales…
c="""
SELECT shops.Store_size, sales.Year, MIN(sales.Sales), AVG(sales.Sales), MAX(sales.Sales)
FROM shops
JOIN sales
ON shops.shopid = sales.shopid
GROUP BY shops.Store_size, sales.Year
"""
query(c)
result = cursor.execute(c).fetchall()

…next I plot the mean sales for medium sized stores against the year…
years=[] # store the year
means = [] # store the mean sales
size = 'medium'
for results in result:
if results[0] == size:
means.append(results[3])
years.append(results[1])
plt.plot(years, means, linestyle = 'dashed', marker = 'o', ms= '5')
plt.title(f"{size} store mean sales")
plt.xlabel("year")
plt.ylabel("sales")
plt.savefig(f"{size}_store_mean_sales.png")
plt.show()

Now we are done, close the connection to the database.
conn.close() # don't forget to close the connection afterwards
I hope this blog was helpful for getting started with the sqlite3 library, to connect to a database, and use a cursor to execute SQL commands in python.
Spent some time on 8kbet456. Good selection of games, and withdrawals were pretty smooth. No complaints from me so far. Give it a shot: 8kbet456
Heard some good things about fc88vn, so I gave it a try. Layout’s not the best, but the games are solid. See for yourself: fc88vn
73betapp? I’ve been using it on my phone. Easy to navigate and haven’t had any crashes yet. Check it out if you’re looking for a mobile option: 73betapp
Very stable platform with a lot of exciting options. I feel safe depositing my funds here. Check out plataformapgwin for a secure bet.
Love the local vibe of this site. It feels tailored for us and the customer support is actually helpful. Glad I found phauronplay.
No more endless loading screens. The login is instant and the connection is stable even on my mobile data. A very seamless gaming experience at jili588casinologin
Fast registration and even faster withdrawals. It is refreshing to find a site that does not make you jump through hoops. Great job 288jililogin.
Great vibes and very fair odds. It is hard to find a site this honest these days. I’m sticking with bd8999vet from now on.
Found this site through a friend and it is legit. The bonuses are actually usable and not just for show. Give bdl8992 a try.
I had a great run yesterday and won big! The graphics are sleek and the gameplay is fair. I will definitely be coming back to korwin39
Really loving the interface here. The loading speed is fast and the games are super smooth. Definitely my new favorite spot to hang out. Check out dreamjili2login
The customer support is actually helpful and responsive which is rare these days. I felt safe depositing my money and the games are genuinely exciting. Love jiliuucasino!
If you are looking for a win, this is the place to be. Everything is transparent and the games are fair. Join solusiwinlogin today.
Found this site through a friend and I am glad I did. The customer support is very responsive and the winning streaks are real. Check out bdgv999 if you want a great experience.
Finally a site that doesn’t lag during peak hours. The login process is quick and everything just works perfectly on my phone. I always use jili30login for my daily gaming sessions.
Had a lucky streak here last night! The site is stable and the games load instantly. If you want a fun time, pkcr777 is the way to go.
This place has a great community and the support team is actually helpful. I had an issue with my account and it was fixed in minutes via ph1xjili.
I felt lucky the moment I joined. The odds are great and the community is very welcoming. Definitely my new favorite spot pkluckybet7
Finally an app that does not crash every five minutes. The login process is seamless and the graphics are top notch. Love how convenient it is to play on the go via evojililoginapp.
Quick installation and no lag at all. It is definitely the best way to get the game running on my phone. Visit pak33gamedownload now.
A hidden gem for gamers. The selection of apps is fantastic and everything works as advertised. Check out in7apkallapp for the best tools.
Quick and secure access every time. I appreciate the stability of this portal. For the fastest entry go with bosku777login.
The winning streaks here are insane. I tried a few others but this one feels way more rewarding. Just log into mahagacor77login and see for yourself.
Just stumbled upon this site and I am already hooked. The speed is amazing and the vibes are just right for a gamer. vn47tg88
I appreciate how secure this site feels. My transactions are always processed quickly without any hassle. Big thanks to 666jililogin
The app version is a game changer. I can play on the go without any hassle and the loading times are super quick. Give sg7772app a try if you like convenience.
I’ve tried a few different sites but this one actually feels fair and exciting. The payouts are decent and the games are addictive. Love m555game.
Had a great run tonight! The bonuses are legit and it is so easy to get started. If you are looking for some action, this is the place. lucky22login
Best experience I’ve had in a while. The customer support is helpful and the bonuses are actually worth it. Give phokjili a shot and see for yourself.
I’ve tried a few sites lately but this one really stands out. The games load fast and the payouts are legit. Highly recommend checking out fk77casino for a great experience.
I appreciate how transparent this platform is with their rules. No hidden tricks, just pure fun and fair play. Big thumbs up for vnd188.
Just what I was looking for. The stability of the app is impressive and everything runs just as it should. Keep it up bdck4444aps
Quick installation and the app is very light on memory. Everything is optimized for a great experience. Get it now at luky888download.
Really solid platform with a great community feel. Everything feels very transparent and fair. Cheers to brwinbrl for the awesome setup.
Easy to navigate and the odds are very competitive. If you are into sports and slots then autobolalogin is the way to go.
Login is seamless and the customer support is actually helpful. I had a small issue with my deposit and they sorted it out instantly. 90winbet90winlogin
Super easy to navigate and the customer support is actually helpful. Definitely a top-tier choice for gamers. Give pkbuji999 a try!
Super easy to navigate and the rewards are actually decent. I love how straightforward everything is here. My new go-to is jilikkklogin
I’ve been playing here for a few weeks now and the experience is top-notch. The games load fast and the payouts are fair. Definitely my new favorite spot! Check out pk89pkrgame
I’ve tried a few platforms but this one really stands out. The payout is fast and the games are super smooth. Definitely my new go-to spot! phsuperace777
The login process is so quick and the site is very user friendly. I had a small issue with my account but the support team fixed it in minutes. Love using panalo777login.
Great selection of slots and the jackpots are actually real. I had a huge win last night and the withdrawal was instant. Love vnnk88nohu so much.
The bonuses for new players are actually generous. I felt welcomed from the moment I signed up. Check out phkkjili for some great promos.
Top notch entertainment and very fair odds. I’ve tried many sites but this one stands out the most in terms of quality. Go to pkca777 now.
Best platform I have used in a long time. The payouts are fast and the games are fair. Highly recommend br3365bet to everyone.
Been using this site for a week now and the experience has been flawless. Very reliable and easy to navigate. Try phmwplay8888
Secure and professional. I feel safe depositing my funds here and the withdrawals are lightning fast. Go to 77888betlogin.
Great platform with very fair odds. I appreciate the transparency and the quick customer support. krikia11 is a winner.
The mobile app is a game changer. I can play my favorite jili games while commuting without any glitches. Get the jili979app if you want convenience on the go.
Super easy to navigate and the bonuses are actually usable. I managed to hit a nice streak yesterday. Highly recommend f168link
Solid experience all around. No glitches, easy navigation, and the rewards are actually attainable. Highly suggest win444top for anyone starting out.
Solid platform with a very fair system. I appreciate the customer support team for being so responsive whenever I had a question. Great experience with bd099bet
Top notch gaming experience! The server is stable and there is zero lag during my sessions. Big thanks to idsuper89 for the quality service.
Had a bit of trouble with other sites but the login process here is a breeze. Everything works perfectly on my mobile phone. Check out smjililogin if you want a hassle free start.
The deposit and withdrawal process here is a breeze. I love how quickly my funds hit the account. Great experience so far with krskrillcasino.
Great local experience and the payment methods are very flexible. It feels like they actually understand what players here want. Highly suggest pisokingph.
As someone who prefers using crypto, this site is a breath of fresh air. Transactions are instant and the privacy is great. kryptocasinokr is perfect for crypto users.
Simply the best experience I have had in a long time. The graphics are crisp and the winning streaks are real. Love 123bvvip
Great vibes and even better rewards. I really appreciate how straightforward the rules are here. Definitely visit bdm444 for some quality entertainment.
I’ve tried a few others, but this one feels the most reliable. The payouts are quick and the interface is very friendly for beginners. jiliuucom
I’ve tried a few platforms lately but this one really stands out. The games are smooth and the payouts are fair. Highly recommend checking out 311jiliparkcasino for a great experience.
The variety of games available here is impressive. I spent the whole weekend exploring different tables and everything works perfectly. Highly recommended for PH players. Explore phjili98
Super impressed with the customer support here. They answered my questions in minutes and helped me get started. Really happy with vnlc168.
The game variety is insane! I spent hours exploring different rooms and everything works perfectly. Highly recommend vnvipwin88 for any serious player.
This is a solid choice for anyone looking for a stable gaming site. No lags and the withdrawals are processed surprisingly fast. ph89jili
Great variety of tables and slots. I’ve won a decent amount here and the process of getting my money out was seamless. You can’t go wrong with 200jilicasinologin.
Great app performance and very stable connection. It is rare to find such a reliable platform these days. Give 09btapp a try if you want a stress-free experience.
Perfect for anyone in the city looking for a quick and easy way to play. Everything is localized and easy to navigate. Shoutout to phmanilaplay!