import sqlite3 import pandas.io.sql as sql con = sqlite3.connect('my_db.db') command = '''select distinct cell_signal_strength_dbm,device_latitude,device_longitude,user_id,timestamp from networkmonitor where network_type !='WIFI' and network_type !='MOBILE/LTE' and device_latitude not NULL and cell_signal_strength_dbm not NULL''' table = sql.read_frame(command, con) table.to_csv('my_db.csv')