jmquintana79
5/15/2018 - 1:13 AM

upload data files

Upload data files in COLAB (Google Notebooks)

## credential Google Drive
!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.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)

## list of files
file_list = drive.ListFile({'q': "'1pISY0iA9_NQ_tqc0-FYbhSqnN60UtAYu' in parents and trashed=false"}).GetList()
for file1 in file_list:
  print('title: %s, id: %s' % (file1['title'], file1['id']))
  if 'train' in file1['title']: train_id = file1['id']
  elif 'test' in file1['title']: test_id = file1['id']
  
  
## load data
train_downloaded = drive.CreateFile({'id': train_id})
train_downloaded.GetContentFile('train.csv')
test_downloaded = drive.CreateFile({'id': test_id})
test_downloaded.GetContentFile('test.csv')


import numpy as np
import pandas as pd

## read data
train = pd.read_csv("train.csv")
test = pd.read_csv("test.csv")
## UPLOAD DATA
from google.colab import files
uploaded = files.upload()
## appear widget to select data file

## READ DATA
import pandas as pd
import io
df = pd.read_csv(io.StringIO(uploaded['train.csv'].decode('utf-8')))