Python 读取存储在Google Drive中的csv文件

Python 读取存储在Google Drive中的csv文件,python,google-drive-api,Python,Google Drive Api,我是Python的初学者。我已经启用了Google API,希望使用python读取存储在我驱动器中的csv文件作为熊猫数据帧。有可能吗 谢谢大家! 您可以这样尝试: import pandas as pd import requests from io import StringIO orig_url='https://drive.google.com/file/d/0B6GhBwm5vaB2ekdlZW5WZnppb28/view?usp=sharing' file_id = orig_

我是Python的初学者。我已经启用了Google API,希望使用python读取存储在我驱动器中的csv文件作为熊猫数据帧。有可能吗

谢谢大家!

您可以这样尝试:

import pandas as pd
import requests
from io import StringIO

orig_url='https://drive.google.com/file/d/0B6GhBwm5vaB2ekdlZW5WZnppb28/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)
dfs = pd.read_csv(csv_raw)

如果将文件夹同步到计算机上,只需指定与此类似的文件路径即可

import pandas as pd

test= pd.read_excel ('C:/Users/person/OneDrive - company/Documents/Projects/cortex/Group_status.xlsx')

print(test)


如果您还想了解如何使用驱动器API,可以遵循此操作。

是的,这是可能的,并且在internet上有完整的文档记录。请在询问之前搜索,例如。嗨,萨菲,谢谢你的回复。它可以工作,但是除了通过链接之外,还有其他方法获取文件id吗?我要读取的文件将保持更新,只有其文件名保持不变。您可以选中一个