Skip to content

Instantly share code, notes, and snippets.

@sany2k8
Forked from jepma/csv-to-pandas.py
Created December 29, 2018 16:00
Show Gist options
  • Select an option

  • Save sany2k8/abfe3f4427d83ef8ea83576fcc81d30a to your computer and use it in GitHub Desktop.

Select an option

Save sany2k8/abfe3f4427d83ef8ea83576fcc81d30a to your computer and use it in GitHub Desktop.
Pandas
import pandas as pd
# Read file
results = pd.read_csv("/tmp/data.csv", encoding='utf-8',sep=',', quoting=csv.QUOTE_ALL)
# Print rows
for row in results:
print(row)
# Iterate over rows
for index, row in data.iterrows():
print(row)
import cx_Oracle
import pandas as pd
# Create connection
connection = cx_Oracle.connect(CONN_STRING)
cursor = connection.cursor()
cursor.execute("SELECT * FROM TABLE")
# Grab metadata
csv_heading = [col[0] for col in cursor.description]
# Grab results
results = cursor.fetchall()
# Write results to `CSV`
pd.DataFrame(results, columns=csv_heading).to_csv("/tmp/data.csv", index=False, encoding='utf-8',sep=',', quoting=csv.QUOTE_ALL)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment