【问题标题】:Reading csv in colab errors在 colab 错误中读取 csv
【发布时间】:2020-09-01 03:31:53
【问题描述】:

我正在尝试将文件导入 c-lab。我试过各种版本https://buomsoo-kim.github.io/colab/2018/04/15/Colab-Importing-CSV-and-JSON-files-in-Google-Colab.md/

#import packages
import pandas as pd
pd.plotting.register_matplotlib_converters()
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
import io
print("Setup Complete")

from google.colab import files
uploaded = files.upload()

# Read the file into a variable power_data
#power_data = pd.read("DE_power prices historical.csv")
data = pd.read_csv('DE_power prices historical.csv', error_bad_lines=False)

不断出现错误: enter image description here

【问题讨论】:

    标签: google-colaboratory


    【解决方案1】:

    尝试使用这种方法,它会更容易一些:

    1. 将 .csv 文件上传到您的 Google 云端硬盘
    2. 在您的 Colab 单元中运行以下代码:

      from google.colab import drive
      drive.mount('/content/drive')
      
    3. 点击输出单元格提供的链接并验证您的 Gmail 帐户

    4. 使用 Pandas 导入,例如:

      power_data = pd.read_csv('/content/drive/My Drive/*filename.csv*')
      

    【讨论】:

      【解决方案2】:

      在 google-colab 中安装 google 驱动器

      from google.colab import drive
      drive.mount('/content/drive')
      

      复制文件路径添加到 URL 变量中

      import pandas as pd
      url = 'add copy path your csv file'
      df=pd.read_csv(url)
      df.head()
      

      【讨论】:

        猜你喜欢
        • 2023-04-02
        • 1970-01-01
        • 2018-06-28
        • 1970-01-01
        • 2021-04-10
        • 1970-01-01
        • 2019-02-17
        • 2021-02-14
        • 1970-01-01
        相关资源
        最近更新 更多