Follow next steps to load .csv files with pandas on Google Colaboratory:
1) Install PyDrive which will be used to access Google Drive:
2) Next code assumes your CSV files are in a folder. It will print out the files in a folder and their unique identifiers. Replace <FOLDER ID> with the long string of numbers and letters in the URL of the folder in Google Drive. If the files are located at the top level of Google Drive, replace <FOLDER ID> with ‘root’.
3) Now the files get pulled into Google Colab. GetContentFile saves the files in the local environment and sets the names of the files.
4) Now comes the easy part. Since the files have been saved to the local environment, load up a saved file, by its filename, into a DataFrame:
1) Install PyDrive which will be used to access Google Drive:
2) Next code assumes your CSV files are in a folder. It will print out the files in a folder and their unique identifiers. Replace <FOLDER ID> with the long string of numbers and letters in the URL of the folder in Google Drive. If the files are located at the top level of Google Drive, replace <FOLDER ID> with ‘root’.
3) Now the files get pulled into Google Colab. GetContentFile saves the files in the local environment and sets the names of the files.
train_downloaded = drive.CreateFile({'id': '<TRAIN_FILE_ID>'})train_downloaded.GetContentFile('train.csv')test_downloaded = drive.CreateFile({'id': '<TEST_FILE_ID>'})test_downloaded.GetContentFile('test.csv') |
4) Now comes the easy part. Since the files have been saved to the local environment, load up a saved file, by its filename, into a DataFrame:
import pandas as pdimport numpy as npdf_train = pd.read_csv('train.csv')df_test = pd.read_csv('test.csv') |
Comments
Post a Comment