Unable to remove Rows from existing csv file in AWS S3 using python, Currently, I was able to read write and append data using my code, but when i try to drop a row, i got the following error
MY CODE
import pandas as pd
import boto3
import csv
Name = "database-2"
Launch_time = "2021-07-09T11:04:80z"
Region = "us-east-2"
data_list = {'Instance_name': [Name],
'Created_time ': [Launch_time],
'Region ': [Region]}
s3_client = boto3.client('s3')
df = pd.DataFrame(data_list)
bytes_to_write = df.to_csv(None, header=None, index=False).encode()
print(bytes_to_write)
file_name = 'blank.csv'
current_data = s3_client.get_object(Bucket='test-lambda', Key=file_name)['Body'].read()
print(current_data)
appended_data = current_data + bytes_to_write
appended_data = appended_data.drop([2], axis=0)
s3_client.put_object(Body=appended_data, Bucket='test-lambda', Key=file_name)
ERROR MESSAGE
Traceback (most recent call last):
File "script.py", line 21, in <module>
appended_data = appended_data.drop([2], axis=0)
AttributeError: 'bytes' object has no attribute 'drop'
how to resolve this? please help me...
What I have tried:
I have tried with a csv file in the local machine then the .drop option is worked