Can't read a file in google colaboratory

后端 未结 4 702
广开言路
广开言路 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

    Install the PyDrive wrapper & import libraries.

    This only needs to be done once per notebook.

    !pip install -U -q PyDrive
    from pydrive.auth import GoogleAuth
    from pydrive.drive import GoogleDrive
    from google.colab import auth
    from oauth2client.client import GoogleCredentials
    

    Authenticate and create the PyDrive client.

    This only needs to be done once per notebook.

    auth.authenticate_user()
    gauth = GoogleAuth()
    gauth.credentials = GoogleCredentials.get_application_default()
    drive = GoogleDrive(gauth)
    

    Download a file based on its file ID.

    A file ID looks like: laggVyWshwcyP6kEI-y_W3P8D26sz

    file_id = 'REPLACE_WITH_YOUR_FILE_ID'
    downloaded = drive.CreateFile({'id': file_id})
    downloaded = drive.CreateFile({'id':'1BH-rffqv_1auzO7tdubfaOwXzf278vJK'}) # replace the id with id of file you want to access
    downloaded.GetContentFile('xyz.csv')  
    
    # Read file as panda dataframe
    import pandas as pd
    xyz = pd.read_csv('xyz.csv') 
    

提交回复
热议问题