Load local data files to Colaboratory

后端 未结 9 761
野趣味
野趣味 2020-12-02 08:47

I just wondering that is it possible to load local data files(like .xlsx or .csv files that on my google drive) into Colaboratory?

9条回答
  •  醉酒成梦
    2020-12-02 09:02

    First, executing this cell should create an inline "Choose Files" button

    from google.colab import files
    uploaded = files.upload()
    

    After selecting your file(s), uploaded will be a dictionary of keys (the file names) and values (the encoded file objects). To decode the files for a library such as Pandas, try

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

    After this your dataframe df should be ready to go

提交回复
热议问题