In [10]:
import sqlite3
input_file = "npidata_20050523-20150111.csv"
counter = 0
db_list = []
with open(input_file) as infile:
for line in infile:
#print line
line = line.replace('"', '')
data = line.split(",")
name = data[6] + " " + data[7] + " " + data[5]
business_name = data[4]
city = data[22]
state = data[23]
if counter > 0:
db_list.append((name, business_name, city, state))
counter += 1
#if counter == 10:
# break
In [11]:
len(db_list)
Out[11]:
In [13]:
db = "./npi_data.db"
conn = sqlite3.connect(db)
conn.text_factory = str
c = conn.cursor()
c.executemany("INSERT INTO npi_table VALUES (?,?,?, ?)",db_list)
conn.commit()
conn.close()
In [14]:
db = "./npi_data.db"
conn = sqlite3.connect(db)
conn.text_factory = str
c = conn.cursor()
In [ ]:
c.execute("SELECT * from npi_table where State='TX' and lower(city)='houston'")
result = c.fetchall()
print result
In [ ]:
c.execute("SELECT * from npi_table where State='TX' and lower(city)!='houston'")
result = c.fetchall()
print result
In [ ]:
c.execute("SELECT * from npi_table where city like 'Z%'")
result = c.fetchall()
print result
In [ ]:
c.execute("SELECT * from npi_table where city like 'Z___'")
result = c.fetchall()
print result
In [ ]:
c.execute("SELECT * from npi_table where name like 'RAHUL%'")
result = c.fetchall()
print result
In [29]:
c.execute("SELECT * from npi_table where name like 'RAHUL%' and state='MA'")
result = c.fetchall()
print result
In [30]:
c.execute("SELECT * from npi_table where name like 'RAHUL%' and state='MA' and lower(city)='boston'")
result = c.fetchall()
print result
In [31]:
conn.close()
In [ ]: