I am currently using pandas within AWS Lambda to create functions in python. I currently have a dataframe and am looking to append a new record to the dataframe. Outside of Lambda, I would normally just append the record to the dataframe. In AWS Lambda, I am using the following code and getting the following error message:
df = pd.read_csv(response['Body'], sep=',')
pd.set_option('display.max_columns', None)
first_name = 'Steve'
last_name = 'Jobs'
name = (first_name + " " + last_name)
firm = 'Apple'
position = 'CEO'
product = 'Macintosh'
date_sent = today
type = 'StreetCat Generated'
current_list = [{'Name': name, 'Firm': firm, 'Position': position, 'Product': product, 'Date Sent': date_sent, 'Type': type}]
df2 = df.append(current_list)
The error message I get is:
{
"errorMessage": "'DataFrame' object has no attribute 'append'",
"errorType": "AttributeError",
"requestId": "7c1a322c-b194-4588-8fce-6aa64a666052",
"stackTrace": [
" File \"/var/task/lambda_function.py\", line 36, in lambda_handler\n df2 = df.append(current_list)\n",
" File \"/opt/python/pandas/core/generic.py\", line 5989, in __getattr__\n return object.__getattribute__(self, name)\n"
]
}
I also tried to manually add the record to the dataframe using the following code:
current_list = [{'Name': name, 'Firm': firm, 'Position': position, 'Product': product, 'Date Sent': date_sent, 'Type': type}]
df2 = df.loc[len(df.index)] = [current_list]
When I attempt to do this, I get an error that there is a mismatch in the number of columns and the row cannot be set. I printed the shape of each of these objects and confirmed they are the same size. Does anybody have suggestions on how to do this?