#!/usr/bin/env python # coding: utf-8 # In[1]: import pandas as pd import sqlite3 as sql # In[3]: wikipedia = pd.read_excel('wikipedia_dataset_flat.xlsx') # In[4]: wikipedia.head() # In[5]: ##Creating a SQLite Database ## STEP 1: Assigning the new SQLte database we are about to create to the variable db_conn. db_conn = sql.connect("wikipedia_dataset.db") # In[6]: ##Since the new database file is empty,(i.e, it has no tables), we need to establish a cursor object that will execute the SQL codes to create the data tables ## STEP 2: The cursor is assigned to the variable c c = db_conn.cursor() # In[24]: ## STEP 4: Create the table that will be included in the database. the will result in empty tables c.execute( """ CREATE TABLE wikipedia_pages ( date INTEGER, page TEXT NOT NULL, visits INTEGER ); """ ) # In[29]: ##STEP 5: Populate the table in the database with the relevant data wikipedia.to_sql('wikipedia', db_conn) # In[31]: wikipedia # In[35]: pd.read_sql("SELECT * FROM wikipedia LIMIT 5", db_conn) # In[ ]: