Getting Google Spreadsheet CSV into A Pandas Dataframe

后端 未结 6 670
死守一世寂寞
死守一世寂寞 2020-12-04 09:31

I uploaded a file to Google spreadsheets (to make a publically accessible example IPython Notebook, with data) I was using the file in it\'s native form could be read into a

6条回答
  •  粉色の甜心
    2020-12-04 10:24

    If the csv file was shared via drive and not via spreadsheet then the below change to the url would work

    #Derive the id from the google drive shareable link.
    #For the file at hand the link is as below
    #
    file_id='1-tjNjMP6w0RUV4GhJWw08ql3wYwsNU69'
    link='https://drive.google.com/uc?export=download&id={FILE_ID}'
    csv_url=link.format(FILE_ID=file_id)
    #The final url would be as below:-
    #csv_url='https://drive.google.com/uc?export=download&id=1-tjNjMP6w0RUV4GhJWw08ql3wYwsNU69'
    df = pd.read_csv(csv_url)
    

    And the dataframe would be (if you just ran the above code)

        a   b   c   d
    0   0   1   2   3
    1   4   5   6   7
    2   8   9   10  11
    3   12  13  14  15
    

    See working code here.

提交回复
热议问题