0

My csv file is below

emp_id,Name,Company
10,Aka,PWC
11,Vee,PWC

My code is below

import boto3
import csv

s3_client = boto3.client('s3')
dynamodb = boto3.resource('dynamodb')

def lambda_handler(event, context):
    bucket = event['Records'][0]['s3']['bucket']['name']
    csv_filename = event['Records'][0]['s3']['object']['key']
    csv_object = s3_client.get_object(Bucket=bucket,Key=csv_filename)
    csvFileReader = csv_object['Body'].read().decode('utf-8')
    employees = csvFileReader.split("\n")
    for emp in employees:
        print (emp)

My Output is below. I need to get rid of first line

emp_id,Name,Company
10,Aka,PC
11,Vee,PC

Expected out is below

10,Aka,PC
11,Vee,PC

1 Answer 1

1

You can remove the first line of your array like

employees = csvFileReader.split("\n")
employees.pop(0)
    for emp in employees:
        print (emp)

I havent found any argument or method to avoid the header in the library documentation https://docs.python.org/3.6/library/csv.html

Another solution could be reading the file with pandas library : Prevent pandas read_csv treating first row as header of column names

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.