【发布时间】:2021-04-29 11:32:47
【问题描述】:
我正在尝试从谷歌驱动器中读取带有熊猫的 cvs 文件。 Pandas 从我的计算机读取它时正确,但是当我尝试从我从谷歌驱动器获取的 URL 中读取它以共享文件时,它似乎正在读取其他内容,或者谷歌驱动器对文件做了一些奇怪的事情。 ..这是我所做的:
alread_url = 'https://drive.google.com/file/d/1am7jNHA6Lewzws_K'
pd.read_csv(alread_url, squeeze=True, error_bad_lines=False)
b'Skipping line 6: expected 1 fields, saw 2\nSkipping line 7: expected 1 fields
\nSkipping line 25: expected 1 fields, saw 2\nSkipping line 42: expected 1 fields, saw
2\nSkipping line 43: expected 1 fields, saw 2... some more similar errors
我把它作为数据帧得到
<!DOCTYPE html>
0 <html lang="en">
1 <head>
2 <meta charset="utf-8">
3 <meta name="google-site-verification" conten...
4 <title>Meet Google Drive – One place for all...
... ...
1647 <script type="text/javascript" nonce="3QmHtC...
1648 'https:\x2F\x2Faccounts.google.com\x2FPassiv...
1649 </script>
1650 </body>
1651 </html>
1652 rows × 1 columns
要说的另一件事是,我在 google colab notebook 中运行了这个...... 主要目标是从谷歌驱动器读取 csv 和 xlsx 文件,而无需在任何地方下载文件,所以,如果你知道该怎么做,我真的不在乎我是否不能解决这个问题。
编辑:这是 pandas 试图读取为 csv 的原始文本:
\n<!DOCTYPE html>\n<html lang="en">\n <head>\n <meta charset="utf-8">\n <meta content="width=300, initial-scale=1" name="viewport">\n <meta name="description" content="Google Drive is a free way to keep your files backed up and easy to reach from any phone, tablet, or computer. Start with 15GB of Google storage – free.">\n <meta name="google-site-verification" content="LrdTUW9psUAMbh4Ia074-BPEVmcpBxF6Gwf0MSgQXZs">\n <title>Meet Google Drive – One place for all your files</title>\n <style>\n @font-face {\n font-family: \'Open Sans\';\n font-style: normal;\n font-weight: 300;\n src: url(//fonts.gstatic.com/s/opensans/v15/mem5YaGs126MiZpBA-UN_r8OUuhs.ttf) format(\'truetype\');\n}\n@font-face {\n font-family: \'Open Sans\';\n font-style: normal;\n font-weight: 400;\n src: url(//fonts.gstatic.com/s/opensans/v15/mem8YaGs126MiZpBA-UFVZ0e.ttf) format(\'truetype\');\n}\n </style>\n <style>\n h1, h2 {\n -webkit-animation-duration: 0.1s;\n -webkit-animation-name: fontfix;\n
【问题讨论】:
-
Google 云端硬盘正在向您的 csv 文件添加一些元数据。看看这个答案是否有帮助 - how to read csv from google drive.
-
是的...已经尝试了所有这些答案,我得到了相同的结果...网址似乎指向另一个文件