I'm trying to get all email addresses in a comma separated format from a specific column. This is coming from a csv temp file in Lambda. My goal is to save that file in s3 with only one column containing the email addresses.
This is what the source data looks like:
Here is my code:
#open file and extract email address
with open('/tmp/maillist.csv', 'w') as mail_file:
wm = csv.writer(mail_file)
mail_list = csv.reader(open('/tmp/filtered.csv', "r"))
for rows in mail_list:
','.join(rows)
wm.writerow(rows[3])
bucket.upload_file('/tmp/maillist.csv', key)
I was hoping to get a result like this:
But instead, I'm getting a result like this:
I also tried this code:
#open file and extract email address
mail_list = csv.reader(open('/tmp/filtered.csv', "r"))
with open('/tmp/maillist.csv', 'w') as mail_file:
wm = csv.writer(mail_file)
wm.writerow(mail_list[3])
bucket.upload_file('/tmp/maillist.csv', key)
But I get this error instead:
Response:
{
"errorMessage": "'_csv.reader' object is not subscriptable",
"errorType": "TypeError",
"stackTrace": [
" File \"/var/task/lambda_function.py\", line 68, in lambda_handler\n wm.writerow(mail_list[3])\n"
Any help is appreciated.