Guest User

Untitled

a guest
Dec 1st, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3.  
  4. import pandas as pd
  5. import psycopg2
  6. conn_dv = psycopg2.connect(database="", user="", password="")
  7.  
  8. def read_csv(filename):
  9. usr_list = pd.read_csv(filename)
  10. res = []
  11. for i in usr_list.values:
  12. res.extend(i)
  13. return tuple(res)
  14.  
  15.  
  16. def sql_to_csv(sql, conn):
  17. df = pd.read_sql_query(sql, conn)
  18. df.to_csv('tmp.csv', index=False)
  19. return df
  20.  
  21.  
  22. if __name__=='__main__':
  23. usr_ids = read_csv('name.csv')
  24. sql = """select * from usr_info where cust_id = {uid};""".format(uid=usr_ids)
  25. df = sql_to_csv(sql, conn_dv)
Add Comment
Please, Sign In to add comment