python pandas read_csv 迭代器使用方法_使用Python读取Dropbox共享的csv文件的内容

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.

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 or any object with a read() method (such as a file handle or StringIO)

get_file(from_path,...

Returns

A dropbox.rest.RESTResponse

RESTResponse

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

Then, should be as easy as:

with client.get_file('/magnum-opus.txt') as f:

p=pandas.read_csv(f)

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

Edited thanks @greg

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值