下面是csv
1,'Chaks, Raj','$300,000', False
2,'Chen, Joe','$250,000', False
3,'Kumar, Harry','$240,000', True
下面是代码
import boto3
import csv
def lambda_handler(event, context):
region='us-east-1'
recList=[]
try:
s3=boto3.client('s3')
dyndb = boto3.client('dynamodb', region_name=region)
confile= s3.get_object(Bucket='csvfolder3', Key='employee.csv')
recList = confile['Body'].read().decode('utf-8').split('\n')
firstrecord=True
csv_reader = csv.reader(recList, delimiter=',', quotechar='"')
for row in csv_reader:
if (firstrecord):
firstrecord=False
continue
empid = row[0]
name = row[1].replace(',','').replace('$','') if row[1] else '-'
salary = row[2].replace(',','').replace('$','') if row[2] else 0
response = dyndb.put_item(
TableName='emplist',
Item={
'empid' : {'N':str(empid)},
'name': {'S':name},
'salary': {'N':str(salary)},
'parttime': {'BOOL':False},
}
)
print('Put succeeded:')
except Exception as e:
print (str(e))
下面是引发的错误:
a bytes-like object is required, not 'str'
从csv更新到DynamoDB时
错误:
An error occurred (ValidationException) when calling the PutItem operation: The parameter cannot be converted to a numeric value: Joe
问题在于你的引号
该文件包含:
但是,您告诉
csv_reader
引号是双引号:因此,只需将其更改为:
相关问题 更多 >
编程相关推荐