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
aysh
  • 493
  • 1
  • 11
  • 23

1 Answers1

0

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

L. Quastana
  • 1,273
  • 1
  • 12
  • 34