Skip to content

Instantly share code, notes, and snippets.

@cirops
Created May 29, 2019 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cirops/ef08763deed628a522288b0d40408bb3 to your computer and use it in GitHub Desktop.
Save cirops/ef08763deed628a522288b0d40408bb3 to your computer and use it in GitHub Desktop.
Sample query for the CNPJ sqlite3 database
import sqlite3
import csv
import pandas as pd
def main():
database_file = "CNPJ_full.db"
conn = conn = sqlite3.connect(database_file)
df = pd.read_sql_query("SELECT * FROM empresas WHERE municipio='PELOTAS'", conn)
df.to_csv('cnpj_empresas_pelotas.csv', quotechar='"', quoting=csv.QUOTE_NONNUMERIC, index=False, encoding='utf-8')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment