Skip to content

Latest commit

 

History

History
26 lines (17 loc) · 737 Bytes

9-importcsv.md

File metadata and controls

26 lines (17 loc) · 737 Bytes

<<< Back - Next >>>

Import data into table

Let's create a database table from an existing csv file.

We're going to cheat a bit by using the Pandas library to import our data.

import pandas
import sqlite3

# make the connection
conn = sqlite3.connect('db.sqlite')

# have Pandas read our CSV
df = pandas.read_csv('nypl_items.csv', low_memory=False)

# convert our data into a SQlite table called 'nypl_items'
df.to_sql('nypl_items', conn)

# print a list of every record in  the table
print (pandas.read_sql_query("SELECT * FROM nypl_items", conn))

<<< Back - Next >>>