I have a pandas Df that I am trying to write to csv but unable to. Here is my code:
_bytes = c_df.to_csv(None).encode()
with fs.open("s3://bucket/key1/_df.csv", 'wb') as f:
f.write(_bytes)
I have a pandas Df that I am trying to write to csv but unable to. Here is my code:
_bytes = c_df.to_csv(None).encode()
with fs.open("s3://bucket/key1/_df.csv", 'wb') as f:
f.write(_bytes)
Have you tried using pandas:
c_df.to_csv('s3://bucket/key1/_df.csv', index=False, header=True)
This helped me:
c_df.to_csv('_df.csv', index=False) # Preserves the header if present
And then uploading separately to s3 using boto3:
s3 = boto3.resource('s3')
s3.meta.client.upload_file(closed_aoi_filename, s3_bucket, os.path.join(key, closed_aoi_filename))
I tried direct solutions to upload pandas df to s3 but wasn't successful. In case anyone has better answers, please let me know. So far this works.