0

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)
1
  • 2
    Can you paste the full error your code is generating? Commented Dec 17, 2018 at 20:30

2 Answers 2

1

Have you tried using pandas:

c_df.to_csv('s3://bucket/key1/_df.csv', index=False, header=True)
Sign up to request clarification or add additional context in comments.

1 Comment

It says 'str' object has no attribute 'to_csv'
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.