I want to append to a csv file, some data from redshift tables, using the pandas
module in python. From python, I can successfully connect and retrieve rows from redshift tables using the psycopg2
module. Now, I am storing datewise data on the csv. So I need to first create a new date column in the csv, then append the data retrieved in that new column.
I am using the following commands to read from redshift tables:
conn=psycopg2.connect( host='my_db_hostname', port=`portnumber`, user='username', password='password', dbname='db')
conn.autocommit = True
cur=conn.cursor()
cur.execute(""" select emp_name, emp_login_count from public.emp_login_detail where login_date=current_date """)
records=cur.fetchall()
cur.close()
Now, I want to append these emp_name and emp_login_count columns to the existing csv. Below is a snapshot of csv:
Everyday I need to add new date column in csv and then I need to put the emp_login_count against respective person's name.
I am new to Pandas and have no idea how to implement this. Can someone please help me out?