【问题标题】:Colab reads a csv file in Google Drive as htmlColab 将 Google Drive 中的 csv 文件读取为 html
【发布时间】:2021-02-14 01:40:00
【问题描述】:

我的 Google 云端硬盘中存储了一个 csv 文件。当我在 Colab 中打开它时,它会像下图一样打开。 Colab 似乎认为它是一个 html 文件。我该怎么办? 供您参考,我知道我可以用 PyDrive 打开它,但是 PyDrive 每次都需要身份验证,所以我需要另一种方式。

df = pd.read_csv('https://drive.google.com/file/d/ 
                 /1c-j4nEO9Pn3E-zf5is5Py3OTG8pXDdrj/view?usp=sharing',
                 encoding='cp949', nrows=100)

【问题讨论】:

    标签: google-drive-api google-colaboratory


    【解决方案1】:

    我发现我可以从 Colab 连接到 Google 云端硬盘,而无需在第一次身份验证后进行其他身份验证。

    第一次认证是这样完成的: https://stackoverflow.com/a/52300696/13474735

    之后,您可以使用以下代码访问您的 Google 云端硬盘:

    from google.colab import drive
    drive.mount('/content/drive')
    df = pd.read_csv('/content/drive/My Drive/xxxx.csv')
    

    【讨论】:

      猜你喜欢
      • 2020-09-17
      • 1970-01-01
      • 2019-05-22
      • 1970-01-01
      • 2021-08-14
      • 2016-01-13
      • 2022-08-20
      • 2022-01-19
      • 1970-01-01
      相关资源
      最近更新 更多