I have a csv file in my s3 bucket and configured aws cli in my local machine. I want to append the data to that csv file whenever I call my python script, but i am not able to do that.
s3_client = boto3.client('s3')
df = pd.DataFrame(data_list)
bytes_to_write = df.to_csv(None, header=None, index=False).encode()
file_name = 'test.csv'
# get the existing file
current_data = s3_client.get_object(Bucket='test-bucket', Key=file_name)
# append
appended_data = current_data + bytes_to_write
# overwrite
s3_client.put_object(Body=appended_data, Bucket='test-bucket', Key=file_name)
enter code here
I have tried the above code but unfortunate couldn't complete the action, i got the following error
Traceback (most recent call last):
File "script.py", line 17, in <module>
appended_data = current_data + bytes_to_write
TypeError: unsupported operand type(s) for +: 'dict' and 'bytes'
Any solution for this? please help me!