0

I will like to know how to export pandas dataframe as csv/txt file to Alicloud OSS. From the documentation in https://www.alibabacloud.com/help/en/doc-detail/88426.html

the closest way I can find is to export it as csv/txt locally on my computer and copy the file to OSS. E.g.

import oss2
auth = oss2.Auth('yourAccessKeyId', 'yourAccessKeySecret')
bucket = oss2.Bucket(auth, 'yourEndpoint', 'examplebucket')
bucket.put_object_from_file('exampleobject.txt', 'D:\\localpath\\examplefile.txt')

Hence will like to know if there is a way to export the file directly to OSS, without the need to export to my computer first. Thank you!

ac123
  • 15
  • 4
  • So you're just dealing with CSV files right? May I know where your data currently is at? – sykez Mar 25 '22 at 02:27
  • The csv data is in my local computer. I managed to figure out in the end. See the code below. Thank you! – ac123 Mar 25 '22 at 06:10

1 Answers1

0

Managed to solve this in the end. Exporting it as csv without the filename using Pandas library will convert the dataframe in python to text without exporting the dataframe.

bucket.put_object('example.txt', df.to_csv(index = False, encoding = 'utf-8-sig'))
ac123
  • 15
  • 4
  • there's no `df` in your question. how do you expected others to answer? – Lei Yang Mar 25 '22 at 06:25
  • It is mentioned in the question 'pandas dataframe'. Maybe I should have made it more clearer. Thanks for the feedback! – ac123 Mar 25 '22 at 08:12