Can't read a file in google colaboratory

后端 未结 4 808
广开言路
广开言路 2021-02-02 17:12

Can\'t read a file in google colaboratory . I have .ipynb file and .csv files in the same directory but when I try to run:

train = pd.read_csv(\"train.csv\") 
<         


        
4条回答
  •  無奈伤痛
    2021-02-02 17:25

    I use windows 10 and this worked perfectly for me. Give it try.

    Add new folder into your drive. Name it what you want. In my case I named it "Colab Notebook". This is folder where I keep my codes and data file.

    First you need to mount your drive. For this run the following one by one

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

    After second command it pops link where the authentication key is. Open this link copy the key, paste and press enter.

    Now type !ls it has to give something like this drive sample_data

    Upload your data file. Either it will be csv or excel file does not matter, but commands will be different for each.

    For csv file

    train = pd.read_csv('/content/drive/My Drive/Colab Notebook/train.csv')
    

    For excel file it's the same just change pandas command and file extension

提交回复
热议问题