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]:
4476420

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


[('RAHUL HARDAS RATHOD', '', 'BROOKLINE', 'MA'), ('RAHUL K SHAH', '', 'BROOKLINE', 'MA'), ('RAHUL J SAWANT', '', 'FRANKLIN', 'MA'), ('RAHUL C DEO', '', 'BROOKLINE', 'MA'), ('RAHUL  CHATURVEDI', '', 'HYANNIS', 'MA'), ('RAHUL K PATEL', '', 'GREENFIELD', 'MA'), ('RAHUL  KAKKAR', '', 'BOSTON', 'MA'), ('RAHULKUMAR  SINGH', '', 'SPRINGFIELD', 'MA'), ('RAHUL ANIL SHETH', '', 'CHESTNUT HILL', 'MA'), ('RAHUL N. SOOD', '', 'WORCESTER', 'MA'), ('RAHUL CHANDRABHAN GUPTA', '', 'BRIGHTON', 'MA'), ('RAHUL SRINIVASA VEDULA', '', 'BOSTON', 'MA'), ('RAHUL  MODI', '', 'BOSTON', 'MA')]

In [30]:
c.execute("SELECT * from npi_table where name like 'RAHUL%' and state='MA' and lower(city)='boston'")
result = c.fetchall()
print result


[('RAHUL  KAKKAR', '', 'BOSTON', 'MA'), ('RAHUL SRINIVASA VEDULA', '', 'BOSTON', 'MA'), ('RAHUL  MODI', '', 'BOSTON', 'MA')]

In [31]:
conn.close()

In [ ]: