Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何使用Pandas将文件写入S3_Python 3.x_Pandas_Amazon Web Services_Amazon S3_Boto3 - Fatal编程技术网

Python 3.x 如何使用Pandas将文件写入S3

Python 3.x 如何使用Pandas将文件写入S3,python-3.x,pandas,amazon-web-services,amazon-s3,boto3,Python 3.x,Pandas,Amazon Web Services,Amazon S3,Boto3,我想将.ann格式的数据帧列写入S3 现在我正在使用下面的代码来实现这一点 df['user_input'].to_csv(ann_file_path, header=None, index=None, sep=' ') 其中ann_file_path是服务器上.ann文件的完整路径 我收到以下错误消息: [Errno 22] Invalid argument: 'https://s3-eu-west-1.amazonaws.com/bucket/sub_folder/somefile.ann

我想将.ann格式的数据帧列写入S3

现在我正在使用下面的代码来实现这一点

df['user_input'].to_csv(ann_file_path, header=None, index=None, sep=' ')
其中ann_file_path是服务器上.ann文件的完整路径

我收到以下错误消息:

[Errno 22] Invalid argument: 'https://s3-eu-west-1.amazonaws.com/bucket/sub_folder/somefile.ann'
为什么我会这样

另外,我是否需要使用Boto3来写文件,还是可以直接在S3上用完整路径写文件


我认为可能需要一些授权,但错误消息似乎与授权相关的内容不同。

我已经解决了。我们需要使用AWS的访问密钥id和密钥进行AWS握手

获取从bucket名称开始的URL,而不是https:/…,因此去掉它之前的任何内容

我的网址:https://s3-eu-west-1.amazonaws.com/bucket/sub_folder/somefile.ann

转换为:bucket/sub_folder/somefile.ann

代码:ann_file_path=ann_file_path.split.com/,1[1]

一旦得到ann_文件路径,我就使用python库将ann文件上传到服务器

bytes_to_write = df['user_input'].to_csv(header=None, index=None).encode()
fs = s3fs.S3FileSystem(key=settings.AWS_ACCESS_KEY_ID, secret=settings.AWS_SECRET_ACCESS_KEY)
with fs.open(ann_file_path, 'wb') as f:
   f.write(bytes_to_write)

将内容放入S3需要凭据握手,您肯定需要boto3或boto3包装器。谢谢,我已经解决了问题并发布了我的答案。我真的需要AWS凭证握手: