Download xlsx file from disk in the collective lab

How can I import an MS-excel file (.xlsx) from a Google drive into colaboratory?

excel_file = drive.CreateFile({'id':'some id'})

works ( drive- object pydrive.drive.GoogleDrive). But,

print excel_file.FetchContent()

returns None. AND

excel_file.content()

throws:

TypeErrorTraceback (last last call) in () ----> 1 excel_file.content ()

TypeError: object '_io.BytesIO' cannot be called

My intention (given some valid "id" file) is to import it as an io object that can be read with pandas read_excel(), and finally get pandas from it.

+4
source share
1 answer

excel_file.GetContentFile, . Pandas read_excel !pip install -q xlrd.

: https://colab.research.google.com/notebook#fileId=1SU176zTQvhflodEzuiacNrzxFQ6fWeWC

:

.xlsx.

.xlsx . URL-: https://drive.google.com/open?id=1Sv4ib5i7CKWhAHZkKg-uitIkS3xwxtXM

. 1Sv4ib5i7CKWhAHZkKg-uitIkS3xwxtXM.

, Colab, . :

file_id = '1Sv4ib5i7CKWhAHZkKg-uitIkS3xwxtXM'
downloaded = drive.CreateFile({'id': file_id})
downloaded.GetContentFile('exported.xlsx')

, Pandas DataFrame:

!pip install -q xlrd
import pandas as pd
df = pd.read_excel('exported.xlsx')
df

!pip install... xlrd, Excel.

+5

Source: https://habr.com/ru/post/1689677/


All Articles