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?
records? You have now, login count inemp_login_countand you want to change that into today's date, right?CSVisn't append friendly, particularly if you want to append columns. You will have to re-read, add the column, and write it back everytime, which gets more expensive with time. I suggest you rethink how you are storing your data. Since the updates are by date, I would suggest you "partition" your dataset by date, and use something like parquet. If you want to keep it simple, you can manage the partitions yourself, and continue usingCSVs.