使用Python读取Dropbox共享的csv文件的内容 [英] Reading the contents of a dropbox shared csv file with Python

查看:151
本文介绍了使用Python读取Dropbox共享的csv文件的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Dropbox API的新手。一位同事共享了一个保管箱文件夹,其中包含大型(450 MB和17 GB之间的各种大小)csv文件。
我想读取Dropbox上的文件而不下载它们。我尝试了很多事情,包括阅读Dropbox API教程和文档以及参考Stackoverflow帖子。

I am new to Dropbox API. A colleague has shared a dropbox folder containing large (various sizes between 450 MB and 17 GB) csv files. I want to read the files on Dropbox without downloading them. I tried many things including reading the Dropbox API tutorials and documentation as well as referring to Stackoverflow post.

我的问题是:读取共享的csv文件的好方法是什么?如果大小允许我,我需要使用pandas.read_csv()读取它们的路径;如果大小太大,则逐行读取。
预先感谢。

My question is: What is a good way to read csv files shared by somebody else and what path I need to use to read them with pandas.read_csv() if size allows me or line by line if size is too large. Thanks in advance.

推荐答案

我没有尝试过,但是...

I didn't try it, but ...

引用熊猫文档


pandas.read_csv(filepath_or_buffer,...

filepath_or_buffer: str,pathlib.Path,py._path.local.LocalPath 或任何具有read()方法的对象(例如文件句柄或StringIO)

filepath_or_buffer : str, pathlib.Path, py._path.local.LocalPath or any object with a read() method (such as a file handle or StringIO)

引用 Dropbox文档


get_file(from_path,...

返回
一个dropbox.rest.RESTResponse

Returns A dropbox.rest.RESTResponse

RESTResponse

对请求的响应可以采用RESTResponse的形式,它们是围绕 socket文件说明的薄包装器托。 read()和close()已实现。

Responses to requests can come in the form of RESTResponse. These are thin wrappers around the socket file descriptor. read() and close() are implemented.

然后,应该很简单:

with client.get_file('/magnum-opus.txt') as f:
    p=pandas.read_csv(f)

其中 pandas.read_csv 调用<$ c $上的 read 方法c> f (保管箱文件处理程序)

Where pandas.read_csv calls read method on f ( dropbox file handler )

已编辑,谢谢@greg

如果您使用以下命令下载文件Dropbox V2 API ,那么您可以检查请求响应的 raw 属性是否处于流模式并具有读取方法。

If you are downloading file with Dropbox V2 API then you may check if raw property of the request response is on stream mode and has read method.:

_, res = dbx.files_download(path)
p=pandas.read_csv(res.raw)

对不起,我没有尝试,只是尝试再回来。如果没有,则必须使用迭代器和手工块。有关详细信息,请参见原始响应内容

sorry, I didn't try it, just try and come back. If not then you must use iterators and hand chunks. More detail at Raw Response Content

这篇关于使用Python读取Dropbox共享的csv文件的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆