在python中,如何读取Google Drive中的大型CSV?

在python中,如何读取Google Drive中的大型CSV?,python,pandas,csv,google-drive-api,Python,Pandas,Csv,Google Drive Api,我在谷歌硬盘中有一个CSV文件(110 MB),我想用Python读取它 我得到了它与Share-Get-link命令的直接链接 我试着这样做,在Python3中: import pandas as pd import requests from io import StringIO orig_url='https://drive.google.com/file/d/1jfLj0k_0BaNuYYZk0Q1IlcgWVvCxb7Yf/view?usp=sharing' file_id = o

我在谷歌硬盘中有一个CSV文件(110 MB),我想用Python读取它

我得到了它与Share-Get-link命令的直接链接

我试着这样做,在Python3中:

import pandas as pd
import requests
from io import StringIO

orig_url='https://drive.google.com/file/d/1jfLj0k_0BaNuYYZk0Q1IlcgWVvCxb7Yf/view?usp=sharing'

file_id = orig_url.split('/')[-2]
dwn_url='https://drive.google.com/uc?export=download&id=' + file_id
url = requests.get(dwn_url).text
csv_raw = StringIO(url)
df = pd.read_csv(csv_raw)
但内容是这样的:

df.head()
    <!DOCTYPE html><html><head><title>Google Drive - Virus scan warning</title><meta http-equiv="content-type" content="text/html; charset=utf-8"/><link href=&#47;static&#47;doclist&#47;client&#47;css&#47;148676949&#45;untrustedcontent.css rel="stylesheet"><link rel="icon" href="https://ssl.gstatic.com/docs/doclist/images/infinite_arrow_favicon_4.ico"/><style nonce="OQ9CeC6eq/6HZpt+pcTCOw">#gbar  #guser{font-size:13px;padding-top:0px !important;}#gbar{height:22px}#guser{padding-bottom:7px !important;text-align:right}.gbh  .gbd{border-top:1px solid #c9d7f1;font-size:1px}.gbh{height:0;position:absolute;top:24px;width:100%}@media all{.gb1{height:22px;margin-right:.5em;vertical-align:top}#gbar{float:left}}a.gb1    a.gb4{text-decoration:underline !important}a.gb1    a.gb4{color:#00c !important}.gbi .gb4{color:#dd8e27 !important}.gbf .gb4{color:#900 !important}
0   </style><script nonce="OQ9CeC6eq/6HZpt+pcTCOw"...   NaN     NaN     NaN     NaN
df.head()
谷歌(Google)驱动谷歌(Google)驱动谷歌(Google)驱动谷歌(Google)驱动谷歌(谷歌)驱动谷歌(谷歌)驱动谷歌(谷歌)驱动谷歌(谷歌)驱动谷歌(谷歌)驱动谷歌(谷歌)驱动谷歌(谷歌)驱动谷歌(谷歌)病毒扫描病毒扫描警告(谷歌)谷歌(谷歌)驱动谷歌(谷歌)驱动谷歌(谷歌)驱动谷歌(谷歌)病毒扫描(谷歌)病毒扫描(谷歌)谷歌(谷歌)驱动谷歌(谷歌)驱动谷歌)驱动谷歌(谷歌)驱动谷歌(谷歌)驱动谷歌(谷歌)驱动谷歌(高度:谷歌)驱动谷歌(高度:谷歌)驱动谷歌(高度:谷歌)驱动谷歌(高度:谷歌(谷歌(高度:谷歌)驱动)谷歌(高度:谷歌(高度:谷歌(高度:22p学校(高度:谷歌)驱动)病毒)驱动)谷歌(谷歌(谷歌(高度:谷歌)驱动)驱动)谷歌(高度:谷歌(高度:谷歌(高度:谷歌)驱动)病毒)谷歌(高度:谷歌(高度:谷歌(谷歌)病毒)驱动)谷歌(谷歌(谷歌)驱动)}a、 gb1 a.gb4{文本装饰:下划线!重要}a.gb1 a.gb4{颜色:#00c!重要}.gbi.gb4{颜色:#dd8e27!重要}.gbf.gb4{颜色:#900!重要}

0我发现有两种方法可以解决这个问题——规定它们必须是可行的,而无需更改文件存储Google驱动器


  • 这是否回答了您的问题谢谢@hatefAlipoor。但我不想用Colab。是否有其他方法?例如,如果文件是公开共享的,并且可以使用API密钥,那么脚本将变得简单。这个怎么样?但是,如果这不是您期望的方向,我很抱歉。是否可以更改加载数据的位置?