Load local data files to Colaboratory










10














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










share|improve this question


























    10














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










    share|improve this question
























      10












      10








      10


      10





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










      share|improve this question













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







      python google-colaboratory






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 16 '17 at 1:25









      northcheng

      53115




      53115






















          7 Answers
          7






          active

          oldest

          votes


















          16














          I was a bit confused by the example for loading local files on first glance as there was no place to specify a file path. All you need to do is copy and paste the recipe to figure this out, but to be clear:



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


          will open an upload dialogue window where you can browse and select your local files for upload.



          Then



          for fn in uploaded.keys():
          print('User uploaded file "name" with length length bytes'.format(
          name=fn, length=len(uploaded[fn])))


          will show you the keys to access what you just uploaded.



          Edit for additional clarification: The dictionary uploaded will have keys of the selected filenames - so if for example you select a file my_test.txt, then you would access that file using uploaded['my_test.txt'].






          share|improve this answer






















          • thanks! I would try it out tonight
            – northcheng
            Nov 28 '17 at 9:36










          • @elphz What happends if the file is an image?
            – Luis Ramon Ramirez Rodriguez
            Mar 8 '18 at 23:36






          • 2




            but how do you load the file with Python afterward? I can't find a single example for that.
            – ivan_bilan
            Mar 11 '18 at 15:34










          • I'm having the same issue as ivan_billan. No problem 'uploading' but then there are no actual examples of how to access the uploaded file afterwards
            – Zachary Nagler
            Mar 11 '18 at 20:09






          • 1




            @LuisRamonRamirezRodriguez - I just tested with a png file, and it looks like it still uploads as a byte string
            – elphz
            Mar 12 '18 at 14:04


















          9














          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






          share|improve this answer




















          • I just ran the import and "files.upload()" line but it is taking forever. What does it actually do? Is it going to upload every files in my google drive?
            – kawingkelvin
            May 16 '18 at 19:37










          • @kawingkelvin If I remember correctly, It should cause a file-selection window to pop up over your notebook. From there you click the files you want. If it's not loading up, maybe something in your browser is preventing the pop-up
            – Zachary Nagler
            May 21 '18 at 22:06










          • I figured out whats wrong and how it's supposed to work, after switching from safari to chrome (FF doesnt work either). it looks like google colab is not friendly to other browsers other than chrome.
            – kawingkelvin
            May 23 '18 at 21:55



















          4














          Putting this out there as an alternative for people who prefer another way to upload more files - this basically allows you to upload your files through Google Drive.



          Run the below code (found this somewhere previously but I can't find the source again - credits to whoever wrote it!):



          !apt-get install -y -qq software-properties-common python-software-properties module-init-tools
          !add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
          !apt-get update -qq 2>&1 > /dev/null
          !apt-get -y install -qq google-drive-ocamlfuse fuse

          from google.colab import auth
          auth.authenticate_user()
          from oauth2client.client import GoogleCredentials
          creds = GoogleCredentials.get_application_default()
          import getpass

          !google-drive-ocamlfuse -headless -id=creds.client_id -secret=creds.client_secret < /dev/null 2>&1 | grep URL
          vcode = getpass.getpass()
          !echo vcode | google-drive-ocamlfuse -headless -id=creds.client_id -secret=creds.client_secret


          Click on the first link that comes up which will prompt you to sign in to Google; after that another will appear which will ask for permission to access to your Google Drive.



          Then, run this which creates a directory named 'drive', and links your Google Drive to it:



          !mkdir -p drive
          !google-drive-ocamlfuse drive


          If you do a !ls now, there will be a directory drive, and if you do a !ls drive you can see all the contents of your Google Drive.



          So for example, if I save my file called abc.txt in a folder called ColabNotebooks in my Google Drive, I can now access it via a path drive/ColabNotebooks/abc.txt






          share|improve this answer


















          • 3




            For the missing source -- that looks like the bit of code at: medium.com/deep-learning-turkey/…
            – Kirk Kittell
            May 5 '18 at 14:20


















          3














          Yes, all of these scenarios are supported.



          For recipes to access local and Drive files, check out the I/O example notebook.



          For access to xls files, you'll want to upload the file to Google Sheets. Then, you can use the gspread recipes in the same I/O example notebook.



          A recently added way to upload local files is to use the 'Files' tab in the right hand side drawer.



          enter image description here



          From there, you can upload a local file using the 'upload' button.



          enter image description here



          (You can also download files by right clicking on them in the file tree.)






          share|improve this answer






























            0














            Say, You have a folder on your Google drive named Colab and a csv is file located there.
            To load this file



            import pandas as pd
            titanic = pd.read_csv(“drive/Colab/Titanic.csv”)
            titanic.head(5)


            Before that, you may need to run these command:



            Run these codes first in order to install the necessary libraries and perform authorization.



            !apt-get install -y -qq software-properties-common python-software-properties module-init-tools
            !add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
            !apt-get update -qq 2>&1 > /dev/null
            !apt-get -y install -qq google-drive-ocamlfuse fuse
            from google.colab import auth
            auth.authenticate_user()
            from oauth2client.client import GoogleCredentials
            creds = GoogleCredentials.get_application_default()
            import getpass
            !google-drive-ocamlfuse -headless -id=creds.client_id -secret=creds.client_secret < /dev/null 2>&1 | grep URL
            vcode = getpass.getpass()
            !echo vcode | google-drive-ocamlfuse -headless -id=creds.client_id -secret=creds.client_secret


            When you run the code above, you should see a result like this:
            enter image description here



            Click the link, copy verification code and paste it to text box.



            After completion of the authorization process,



            mount your Google Drive:



            !mkdir -p drive
            !google-drive-ocamlfuse drive





            share|improve this answer






























              0














              It's a 2 step process.



              Step 1 : First invoke a file selector with in your colab notebook with the following code



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


              this will take you to a file browser window



              step 2 : To load the content of the file into Pandas dataframe, use the following code



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





              share|improve this answer






















              • You should always format your code using the button or CTRL-K.
                – Mr. T
                Jun 23 '18 at 9:20


















              0














              To get data from your system to colab try this:



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


              Choose the file you want to upload and hit enter and its done.
              For example, I have uploaded an image and displayed it using the code below:



              import cv2
              import numpy as np
              from matplotlib import pyplot as plt

              img = cv2.imread('image.jpg')
              img_cvt = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

              plt.imshow(img_cvt)
              plt.show()





              share|improve this answer






















                Your Answer






                StackExchange.ifUsing("editor", function ()
                StackExchange.using("externalEditor", function ()
                StackExchange.using("snippets", function ()
                StackExchange.snippets.init();
                );
                );
                , "code-snippets");

                StackExchange.ready(function()
                var channelOptions =
                tags: "".split(" "),
                id: "1"
                ;
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function()
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled)
                StackExchange.using("snippets", function()
                createEditor();
                );

                else
                createEditor();

                );

                function createEditor()
                StackExchange.prepareEditor(
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader:
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                ,
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                );



                );













                draft saved

                draft discarded


















                StackExchange.ready(
                function ()
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f47320052%2fload-local-data-files-to-colaboratory%23new-answer', 'question_page');

                );

                Post as a guest















                Required, but never shown

























                7 Answers
                7






                active

                oldest

                votes








                7 Answers
                7






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                16














                I was a bit confused by the example for loading local files on first glance as there was no place to specify a file path. All you need to do is copy and paste the recipe to figure this out, but to be clear:



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


                will open an upload dialogue window where you can browse and select your local files for upload.



                Then



                for fn in uploaded.keys():
                print('User uploaded file "name" with length length bytes'.format(
                name=fn, length=len(uploaded[fn])))


                will show you the keys to access what you just uploaded.



                Edit for additional clarification: The dictionary uploaded will have keys of the selected filenames - so if for example you select a file my_test.txt, then you would access that file using uploaded['my_test.txt'].






                share|improve this answer






















                • thanks! I would try it out tonight
                  – northcheng
                  Nov 28 '17 at 9:36










                • @elphz What happends if the file is an image?
                  – Luis Ramon Ramirez Rodriguez
                  Mar 8 '18 at 23:36






                • 2




                  but how do you load the file with Python afterward? I can't find a single example for that.
                  – ivan_bilan
                  Mar 11 '18 at 15:34










                • I'm having the same issue as ivan_billan. No problem 'uploading' but then there are no actual examples of how to access the uploaded file afterwards
                  – Zachary Nagler
                  Mar 11 '18 at 20:09






                • 1




                  @LuisRamonRamirezRodriguez - I just tested with a png file, and it looks like it still uploads as a byte string
                  – elphz
                  Mar 12 '18 at 14:04















                16














                I was a bit confused by the example for loading local files on first glance as there was no place to specify a file path. All you need to do is copy and paste the recipe to figure this out, but to be clear:



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


                will open an upload dialogue window where you can browse and select your local files for upload.



                Then



                for fn in uploaded.keys():
                print('User uploaded file "name" with length length bytes'.format(
                name=fn, length=len(uploaded[fn])))


                will show you the keys to access what you just uploaded.



                Edit for additional clarification: The dictionary uploaded will have keys of the selected filenames - so if for example you select a file my_test.txt, then you would access that file using uploaded['my_test.txt'].






                share|improve this answer






















                • thanks! I would try it out tonight
                  – northcheng
                  Nov 28 '17 at 9:36










                • @elphz What happends if the file is an image?
                  – Luis Ramon Ramirez Rodriguez
                  Mar 8 '18 at 23:36






                • 2




                  but how do you load the file with Python afterward? I can't find a single example for that.
                  – ivan_bilan
                  Mar 11 '18 at 15:34










                • I'm having the same issue as ivan_billan. No problem 'uploading' but then there are no actual examples of how to access the uploaded file afterwards
                  – Zachary Nagler
                  Mar 11 '18 at 20:09






                • 1




                  @LuisRamonRamirezRodriguez - I just tested with a png file, and it looks like it still uploads as a byte string
                  – elphz
                  Mar 12 '18 at 14:04













                16












                16








                16






                I was a bit confused by the example for loading local files on first glance as there was no place to specify a file path. All you need to do is copy and paste the recipe to figure this out, but to be clear:



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


                will open an upload dialogue window where you can browse and select your local files for upload.



                Then



                for fn in uploaded.keys():
                print('User uploaded file "name" with length length bytes'.format(
                name=fn, length=len(uploaded[fn])))


                will show you the keys to access what you just uploaded.



                Edit for additional clarification: The dictionary uploaded will have keys of the selected filenames - so if for example you select a file my_test.txt, then you would access that file using uploaded['my_test.txt'].






                share|improve this answer














                I was a bit confused by the example for loading local files on first glance as there was no place to specify a file path. All you need to do is copy and paste the recipe to figure this out, but to be clear:



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


                will open an upload dialogue window where you can browse and select your local files for upload.



                Then



                for fn in uploaded.keys():
                print('User uploaded file "name" with length length bytes'.format(
                name=fn, length=len(uploaded[fn])))


                will show you the keys to access what you just uploaded.



                Edit for additional clarification: The dictionary uploaded will have keys of the selected filenames - so if for example you select a file my_test.txt, then you would access that file using uploaded['my_test.txt'].







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 12 '18 at 14:09

























                answered Nov 16 '17 at 16:50









                elphz

                1,143918




                1,143918











                • thanks! I would try it out tonight
                  – northcheng
                  Nov 28 '17 at 9:36










                • @elphz What happends if the file is an image?
                  – Luis Ramon Ramirez Rodriguez
                  Mar 8 '18 at 23:36






                • 2




                  but how do you load the file with Python afterward? I can't find a single example for that.
                  – ivan_bilan
                  Mar 11 '18 at 15:34










                • I'm having the same issue as ivan_billan. No problem 'uploading' but then there are no actual examples of how to access the uploaded file afterwards
                  – Zachary Nagler
                  Mar 11 '18 at 20:09






                • 1




                  @LuisRamonRamirezRodriguez - I just tested with a png file, and it looks like it still uploads as a byte string
                  – elphz
                  Mar 12 '18 at 14:04
















                • thanks! I would try it out tonight
                  – northcheng
                  Nov 28 '17 at 9:36










                • @elphz What happends if the file is an image?
                  – Luis Ramon Ramirez Rodriguez
                  Mar 8 '18 at 23:36






                • 2




                  but how do you load the file with Python afterward? I can't find a single example for that.
                  – ivan_bilan
                  Mar 11 '18 at 15:34










                • I'm having the same issue as ivan_billan. No problem 'uploading' but then there are no actual examples of how to access the uploaded file afterwards
                  – Zachary Nagler
                  Mar 11 '18 at 20:09






                • 1




                  @LuisRamonRamirezRodriguez - I just tested with a png file, and it looks like it still uploads as a byte string
                  – elphz
                  Mar 12 '18 at 14:04















                thanks! I would try it out tonight
                – northcheng
                Nov 28 '17 at 9:36




                thanks! I would try it out tonight
                – northcheng
                Nov 28 '17 at 9:36












                @elphz What happends if the file is an image?
                – Luis Ramon Ramirez Rodriguez
                Mar 8 '18 at 23:36




                @elphz What happends if the file is an image?
                – Luis Ramon Ramirez Rodriguez
                Mar 8 '18 at 23:36




                2




                2




                but how do you load the file with Python afterward? I can't find a single example for that.
                – ivan_bilan
                Mar 11 '18 at 15:34




                but how do you load the file with Python afterward? I can't find a single example for that.
                – ivan_bilan
                Mar 11 '18 at 15:34












                I'm having the same issue as ivan_billan. No problem 'uploading' but then there are no actual examples of how to access the uploaded file afterwards
                – Zachary Nagler
                Mar 11 '18 at 20:09




                I'm having the same issue as ivan_billan. No problem 'uploading' but then there are no actual examples of how to access the uploaded file afterwards
                – Zachary Nagler
                Mar 11 '18 at 20:09




                1




                1




                @LuisRamonRamirezRodriguez - I just tested with a png file, and it looks like it still uploads as a byte string
                – elphz
                Mar 12 '18 at 14:04




                @LuisRamonRamirezRodriguez - I just tested with a png file, and it looks like it still uploads as a byte string
                – elphz
                Mar 12 '18 at 14:04













                9














                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






                share|improve this answer




















                • I just ran the import and "files.upload()" line but it is taking forever. What does it actually do? Is it going to upload every files in my google drive?
                  – kawingkelvin
                  May 16 '18 at 19:37










                • @kawingkelvin If I remember correctly, It should cause a file-selection window to pop up over your notebook. From there you click the files you want. If it's not loading up, maybe something in your browser is preventing the pop-up
                  – Zachary Nagler
                  May 21 '18 at 22:06










                • I figured out whats wrong and how it's supposed to work, after switching from safari to chrome (FF doesnt work either). it looks like google colab is not friendly to other browsers other than chrome.
                  – kawingkelvin
                  May 23 '18 at 21:55
















                9














                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






                share|improve this answer




















                • I just ran the import and "files.upload()" line but it is taking forever. What does it actually do? Is it going to upload every files in my google drive?
                  – kawingkelvin
                  May 16 '18 at 19:37










                • @kawingkelvin If I remember correctly, It should cause a file-selection window to pop up over your notebook. From there you click the files you want. If it's not loading up, maybe something in your browser is preventing the pop-up
                  – Zachary Nagler
                  May 21 '18 at 22:06










                • I figured out whats wrong and how it's supposed to work, after switching from safari to chrome (FF doesnt work either). it looks like google colab is not friendly to other browsers other than chrome.
                  – kawingkelvin
                  May 23 '18 at 21:55














                9












                9








                9






                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






                share|improve this answer












                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







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 12 '18 at 1:05









                Zachary Nagler

                30839




                30839











                • I just ran the import and "files.upload()" line but it is taking forever. What does it actually do? Is it going to upload every files in my google drive?
                  – kawingkelvin
                  May 16 '18 at 19:37










                • @kawingkelvin If I remember correctly, It should cause a file-selection window to pop up over your notebook. From there you click the files you want. If it's not loading up, maybe something in your browser is preventing the pop-up
                  – Zachary Nagler
                  May 21 '18 at 22:06










                • I figured out whats wrong and how it's supposed to work, after switching from safari to chrome (FF doesnt work either). it looks like google colab is not friendly to other browsers other than chrome.
                  – kawingkelvin
                  May 23 '18 at 21:55

















                • I just ran the import and "files.upload()" line but it is taking forever. What does it actually do? Is it going to upload every files in my google drive?
                  – kawingkelvin
                  May 16 '18 at 19:37










                • @kawingkelvin If I remember correctly, It should cause a file-selection window to pop up over your notebook. From there you click the files you want. If it's not loading up, maybe something in your browser is preventing the pop-up
                  – Zachary Nagler
                  May 21 '18 at 22:06










                • I figured out whats wrong and how it's supposed to work, after switching from safari to chrome (FF doesnt work either). it looks like google colab is not friendly to other browsers other than chrome.
                  – kawingkelvin
                  May 23 '18 at 21:55
















                I just ran the import and "files.upload()" line but it is taking forever. What does it actually do? Is it going to upload every files in my google drive?
                – kawingkelvin
                May 16 '18 at 19:37




                I just ran the import and "files.upload()" line but it is taking forever. What does it actually do? Is it going to upload every files in my google drive?
                – kawingkelvin
                May 16 '18 at 19:37












                @kawingkelvin If I remember correctly, It should cause a file-selection window to pop up over your notebook. From there you click the files you want. If it's not loading up, maybe something in your browser is preventing the pop-up
                – Zachary Nagler
                May 21 '18 at 22:06




                @kawingkelvin If I remember correctly, It should cause a file-selection window to pop up over your notebook. From there you click the files you want. If it's not loading up, maybe something in your browser is preventing the pop-up
                – Zachary Nagler
                May 21 '18 at 22:06












                I figured out whats wrong and how it's supposed to work, after switching from safari to chrome (FF doesnt work either). it looks like google colab is not friendly to other browsers other than chrome.
                – kawingkelvin
                May 23 '18 at 21:55





                I figured out whats wrong and how it's supposed to work, after switching from safari to chrome (FF doesnt work either). it looks like google colab is not friendly to other browsers other than chrome.
                – kawingkelvin
                May 23 '18 at 21:55












                4














                Putting this out there as an alternative for people who prefer another way to upload more files - this basically allows you to upload your files through Google Drive.



                Run the below code (found this somewhere previously but I can't find the source again - credits to whoever wrote it!):



                !apt-get install -y -qq software-properties-common python-software-properties module-init-tools
                !add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
                !apt-get update -qq 2>&1 > /dev/null
                !apt-get -y install -qq google-drive-ocamlfuse fuse

                from google.colab import auth
                auth.authenticate_user()
                from oauth2client.client import GoogleCredentials
                creds = GoogleCredentials.get_application_default()
                import getpass

                !google-drive-ocamlfuse -headless -id=creds.client_id -secret=creds.client_secret < /dev/null 2>&1 | grep URL
                vcode = getpass.getpass()
                !echo vcode | google-drive-ocamlfuse -headless -id=creds.client_id -secret=creds.client_secret


                Click on the first link that comes up which will prompt you to sign in to Google; after that another will appear which will ask for permission to access to your Google Drive.



                Then, run this which creates a directory named 'drive', and links your Google Drive to it:



                !mkdir -p drive
                !google-drive-ocamlfuse drive


                If you do a !ls now, there will be a directory drive, and if you do a !ls drive you can see all the contents of your Google Drive.



                So for example, if I save my file called abc.txt in a folder called ColabNotebooks in my Google Drive, I can now access it via a path drive/ColabNotebooks/abc.txt






                share|improve this answer


















                • 3




                  For the missing source -- that looks like the bit of code at: medium.com/deep-learning-turkey/…
                  – Kirk Kittell
                  May 5 '18 at 14:20















                4














                Putting this out there as an alternative for people who prefer another way to upload more files - this basically allows you to upload your files through Google Drive.



                Run the below code (found this somewhere previously but I can't find the source again - credits to whoever wrote it!):



                !apt-get install -y -qq software-properties-common python-software-properties module-init-tools
                !add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
                !apt-get update -qq 2>&1 > /dev/null
                !apt-get -y install -qq google-drive-ocamlfuse fuse

                from google.colab import auth
                auth.authenticate_user()
                from oauth2client.client import GoogleCredentials
                creds = GoogleCredentials.get_application_default()
                import getpass

                !google-drive-ocamlfuse -headless -id=creds.client_id -secret=creds.client_secret < /dev/null 2>&1 | grep URL
                vcode = getpass.getpass()
                !echo vcode | google-drive-ocamlfuse -headless -id=creds.client_id -secret=creds.client_secret


                Click on the first link that comes up which will prompt you to sign in to Google; after that another will appear which will ask for permission to access to your Google Drive.



                Then, run this which creates a directory named 'drive', and links your Google Drive to it:



                !mkdir -p drive
                !google-drive-ocamlfuse drive


                If you do a !ls now, there will be a directory drive, and if you do a !ls drive you can see all the contents of your Google Drive.



                So for example, if I save my file called abc.txt in a folder called ColabNotebooks in my Google Drive, I can now access it via a path drive/ColabNotebooks/abc.txt






                share|improve this answer


















                • 3




                  For the missing source -- that looks like the bit of code at: medium.com/deep-learning-turkey/…
                  – Kirk Kittell
                  May 5 '18 at 14:20













                4












                4








                4






                Putting this out there as an alternative for people who prefer another way to upload more files - this basically allows you to upload your files through Google Drive.



                Run the below code (found this somewhere previously but I can't find the source again - credits to whoever wrote it!):



                !apt-get install -y -qq software-properties-common python-software-properties module-init-tools
                !add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
                !apt-get update -qq 2>&1 > /dev/null
                !apt-get -y install -qq google-drive-ocamlfuse fuse

                from google.colab import auth
                auth.authenticate_user()
                from oauth2client.client import GoogleCredentials
                creds = GoogleCredentials.get_application_default()
                import getpass

                !google-drive-ocamlfuse -headless -id=creds.client_id -secret=creds.client_secret < /dev/null 2>&1 | grep URL
                vcode = getpass.getpass()
                !echo vcode | google-drive-ocamlfuse -headless -id=creds.client_id -secret=creds.client_secret


                Click on the first link that comes up which will prompt you to sign in to Google; after that another will appear which will ask for permission to access to your Google Drive.



                Then, run this which creates a directory named 'drive', and links your Google Drive to it:



                !mkdir -p drive
                !google-drive-ocamlfuse drive


                If you do a !ls now, there will be a directory drive, and if you do a !ls drive you can see all the contents of your Google Drive.



                So for example, if I save my file called abc.txt in a folder called ColabNotebooks in my Google Drive, I can now access it via a path drive/ColabNotebooks/abc.txt






                share|improve this answer














                Putting this out there as an alternative for people who prefer another way to upload more files - this basically allows you to upload your files through Google Drive.



                Run the below code (found this somewhere previously but I can't find the source again - credits to whoever wrote it!):



                !apt-get install -y -qq software-properties-common python-software-properties module-init-tools
                !add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
                !apt-get update -qq 2>&1 > /dev/null
                !apt-get -y install -qq google-drive-ocamlfuse fuse

                from google.colab import auth
                auth.authenticate_user()
                from oauth2client.client import GoogleCredentials
                creds = GoogleCredentials.get_application_default()
                import getpass

                !google-drive-ocamlfuse -headless -id=creds.client_id -secret=creds.client_secret < /dev/null 2>&1 | grep URL
                vcode = getpass.getpass()
                !echo vcode | google-drive-ocamlfuse -headless -id=creds.client_id -secret=creds.client_secret


                Click on the first link that comes up which will prompt you to sign in to Google; after that another will appear which will ask for permission to access to your Google Drive.



                Then, run this which creates a directory named 'drive', and links your Google Drive to it:



                !mkdir -p drive
                !google-drive-ocamlfuse drive


                If you do a !ls now, there will be a directory drive, and if you do a !ls drive you can see all the contents of your Google Drive.



                So for example, if I save my file called abc.txt in a folder called ColabNotebooks in my Google Drive, I can now access it via a path drive/ColabNotebooks/abc.txt







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 17 '18 at 2:32

























                answered Mar 17 '18 at 2:23









                yl_low

                21429




                21429







                • 3




                  For the missing source -- that looks like the bit of code at: medium.com/deep-learning-turkey/…
                  – Kirk Kittell
                  May 5 '18 at 14:20












                • 3




                  For the missing source -- that looks like the bit of code at: medium.com/deep-learning-turkey/…
                  – Kirk Kittell
                  May 5 '18 at 14:20







                3




                3




                For the missing source -- that looks like the bit of code at: medium.com/deep-learning-turkey/…
                – Kirk Kittell
                May 5 '18 at 14:20




                For the missing source -- that looks like the bit of code at: medium.com/deep-learning-turkey/…
                – Kirk Kittell
                May 5 '18 at 14:20











                3














                Yes, all of these scenarios are supported.



                For recipes to access local and Drive files, check out the I/O example notebook.



                For access to xls files, you'll want to upload the file to Google Sheets. Then, you can use the gspread recipes in the same I/O example notebook.



                A recently added way to upload local files is to use the 'Files' tab in the right hand side drawer.



                enter image description here



                From there, you can upload a local file using the 'upload' button.



                enter image description here



                (You can also download files by right clicking on them in the file tree.)






                share|improve this answer



























                  3














                  Yes, all of these scenarios are supported.



                  For recipes to access local and Drive files, check out the I/O example notebook.



                  For access to xls files, you'll want to upload the file to Google Sheets. Then, you can use the gspread recipes in the same I/O example notebook.



                  A recently added way to upload local files is to use the 'Files' tab in the right hand side drawer.



                  enter image description here



                  From there, you can upload a local file using the 'upload' button.



                  enter image description here



                  (You can also download files by right clicking on them in the file tree.)






                  share|improve this answer

























                    3












                    3








                    3






                    Yes, all of these scenarios are supported.



                    For recipes to access local and Drive files, check out the I/O example notebook.



                    For access to xls files, you'll want to upload the file to Google Sheets. Then, you can use the gspread recipes in the same I/O example notebook.



                    A recently added way to upload local files is to use the 'Files' tab in the right hand side drawer.



                    enter image description here



                    From there, you can upload a local file using the 'upload' button.



                    enter image description here



                    (You can also download files by right clicking on them in the file tree.)






                    share|improve this answer














                    Yes, all of these scenarios are supported.



                    For recipes to access local and Drive files, check out the I/O example notebook.



                    For access to xls files, you'll want to upload the file to Google Sheets. Then, you can use the gspread recipes in the same I/O example notebook.



                    A recently added way to upload local files is to use the 'Files' tab in the right hand side drawer.



                    enter image description here



                    From there, you can upload a local file using the 'upload' button.



                    enter image description here



                    (You can also download files by right clicking on them in the file tree.)







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Aug 22 '18 at 22:34

























                    answered Nov 16 '17 at 1:51









                    Bob Smith

                    6,2072027




                    6,2072027





















                        0














                        Say, You have a folder on your Google drive named Colab and a csv is file located there.
                        To load this file



                        import pandas as pd
                        titanic = pd.read_csv(“drive/Colab/Titanic.csv”)
                        titanic.head(5)


                        Before that, you may need to run these command:



                        Run these codes first in order to install the necessary libraries and perform authorization.



                        !apt-get install -y -qq software-properties-common python-software-properties module-init-tools
                        !add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
                        !apt-get update -qq 2>&1 > /dev/null
                        !apt-get -y install -qq google-drive-ocamlfuse fuse
                        from google.colab import auth
                        auth.authenticate_user()
                        from oauth2client.client import GoogleCredentials
                        creds = GoogleCredentials.get_application_default()
                        import getpass
                        !google-drive-ocamlfuse -headless -id=creds.client_id -secret=creds.client_secret < /dev/null 2>&1 | grep URL
                        vcode = getpass.getpass()
                        !echo vcode | google-drive-ocamlfuse -headless -id=creds.client_id -secret=creds.client_secret


                        When you run the code above, you should see a result like this:
                        enter image description here



                        Click the link, copy verification code and paste it to text box.



                        After completion of the authorization process,



                        mount your Google Drive:



                        !mkdir -p drive
                        !google-drive-ocamlfuse drive





                        share|improve this answer



























                          0














                          Say, You have a folder on your Google drive named Colab and a csv is file located there.
                          To load this file



                          import pandas as pd
                          titanic = pd.read_csv(“drive/Colab/Titanic.csv”)
                          titanic.head(5)


                          Before that, you may need to run these command:



                          Run these codes first in order to install the necessary libraries and perform authorization.



                          !apt-get install -y -qq software-properties-common python-software-properties module-init-tools
                          !add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
                          !apt-get update -qq 2>&1 > /dev/null
                          !apt-get -y install -qq google-drive-ocamlfuse fuse
                          from google.colab import auth
                          auth.authenticate_user()
                          from oauth2client.client import GoogleCredentials
                          creds = GoogleCredentials.get_application_default()
                          import getpass
                          !google-drive-ocamlfuse -headless -id=creds.client_id -secret=creds.client_secret < /dev/null 2>&1 | grep URL
                          vcode = getpass.getpass()
                          !echo vcode | google-drive-ocamlfuse -headless -id=creds.client_id -secret=creds.client_secret


                          When you run the code above, you should see a result like this:
                          enter image description here



                          Click the link, copy verification code and paste it to text box.



                          After completion of the authorization process,



                          mount your Google Drive:



                          !mkdir -p drive
                          !google-drive-ocamlfuse drive





                          share|improve this answer

























                            0












                            0








                            0






                            Say, You have a folder on your Google drive named Colab and a csv is file located there.
                            To load this file



                            import pandas as pd
                            titanic = pd.read_csv(“drive/Colab/Titanic.csv”)
                            titanic.head(5)


                            Before that, you may need to run these command:



                            Run these codes first in order to install the necessary libraries and perform authorization.



                            !apt-get install -y -qq software-properties-common python-software-properties module-init-tools
                            !add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
                            !apt-get update -qq 2>&1 > /dev/null
                            !apt-get -y install -qq google-drive-ocamlfuse fuse
                            from google.colab import auth
                            auth.authenticate_user()
                            from oauth2client.client import GoogleCredentials
                            creds = GoogleCredentials.get_application_default()
                            import getpass
                            !google-drive-ocamlfuse -headless -id=creds.client_id -secret=creds.client_secret < /dev/null 2>&1 | grep URL
                            vcode = getpass.getpass()
                            !echo vcode | google-drive-ocamlfuse -headless -id=creds.client_id -secret=creds.client_secret


                            When you run the code above, you should see a result like this:
                            enter image description here



                            Click the link, copy verification code and paste it to text box.



                            After completion of the authorization process,



                            mount your Google Drive:



                            !mkdir -p drive
                            !google-drive-ocamlfuse drive





                            share|improve this answer














                            Say, You have a folder on your Google drive named Colab and a csv is file located there.
                            To load this file



                            import pandas as pd
                            titanic = pd.read_csv(“drive/Colab/Titanic.csv”)
                            titanic.head(5)


                            Before that, you may need to run these command:



                            Run these codes first in order to install the necessary libraries and perform authorization.



                            !apt-get install -y -qq software-properties-common python-software-properties module-init-tools
                            !add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
                            !apt-get update -qq 2>&1 > /dev/null
                            !apt-get -y install -qq google-drive-ocamlfuse fuse
                            from google.colab import auth
                            auth.authenticate_user()
                            from oauth2client.client import GoogleCredentials
                            creds = GoogleCredentials.get_application_default()
                            import getpass
                            !google-drive-ocamlfuse -headless -id=creds.client_id -secret=creds.client_secret < /dev/null 2>&1 | grep URL
                            vcode = getpass.getpass()
                            !echo vcode | google-drive-ocamlfuse -headless -id=creds.client_id -secret=creds.client_secret


                            When you run the code above, you should see a result like this:
                            enter image description here



                            Click the link, copy verification code and paste it to text box.



                            After completion of the authorization process,



                            mount your Google Drive:



                            !mkdir -p drive
                            !google-drive-ocamlfuse drive






                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Mar 23 '18 at 4:52

























                            answered Mar 23 '18 at 3:50









                            Sudarshan

                            437621




                            437621





















                                0














                                It's a 2 step process.



                                Step 1 : First invoke a file selector with in your colab notebook with the following code



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


                                this will take you to a file browser window



                                step 2 : To load the content of the file into Pandas dataframe, use the following code



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





                                share|improve this answer






















                                • You should always format your code using the button or CTRL-K.
                                  – Mr. T
                                  Jun 23 '18 at 9:20















                                0














                                It's a 2 step process.



                                Step 1 : First invoke a file selector with in your colab notebook with the following code



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


                                this will take you to a file browser window



                                step 2 : To load the content of the file into Pandas dataframe, use the following code



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





                                share|improve this answer






















                                • You should always format your code using the button or CTRL-K.
                                  – Mr. T
                                  Jun 23 '18 at 9:20













                                0












                                0








                                0






                                It's a 2 step process.



                                Step 1 : First invoke a file selector with in your colab notebook with the following code



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


                                this will take you to a file browser window



                                step 2 : To load the content of the file into Pandas dataframe, use the following code



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





                                share|improve this answer














                                It's a 2 step process.



                                Step 1 : First invoke a file selector with in your colab notebook with the following code



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


                                this will take you to a file browser window



                                step 2 : To load the content of the file into Pandas dataframe, use the following code



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






                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Jun 23 '18 at 9:19









                                Mr. T

                                4,18791535




                                4,18791535










                                answered Jun 23 '18 at 8:57









                                Sri ram

                                11




                                11











                                • You should always format your code using the button or CTRL-K.
                                  – Mr. T
                                  Jun 23 '18 at 9:20
















                                • You should always format your code using the button or CTRL-K.
                                  – Mr. T
                                  Jun 23 '18 at 9:20















                                You should always format your code using the button or CTRL-K.
                                – Mr. T
                                Jun 23 '18 at 9:20




                                You should always format your code using the button or CTRL-K.
                                – Mr. T
                                Jun 23 '18 at 9:20











                                0














                                To get data from your system to colab try this:



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


                                Choose the file you want to upload and hit enter and its done.
                                For example, I have uploaded an image and displayed it using the code below:



                                import cv2
                                import numpy as np
                                from matplotlib import pyplot as plt

                                img = cv2.imread('image.jpg')
                                img_cvt = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

                                plt.imshow(img_cvt)
                                plt.show()





                                share|improve this answer



























                                  0














                                  To get data from your system to colab try this:



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


                                  Choose the file you want to upload and hit enter and its done.
                                  For example, I have uploaded an image and displayed it using the code below:



                                  import cv2
                                  import numpy as np
                                  from matplotlib import pyplot as plt

                                  img = cv2.imread('image.jpg')
                                  img_cvt = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

                                  plt.imshow(img_cvt)
                                  plt.show()





                                  share|improve this answer

























                                    0












                                    0








                                    0






                                    To get data from your system to colab try this:



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


                                    Choose the file you want to upload and hit enter and its done.
                                    For example, I have uploaded an image and displayed it using the code below:



                                    import cv2
                                    import numpy as np
                                    from matplotlib import pyplot as plt

                                    img = cv2.imread('image.jpg')
                                    img_cvt = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

                                    plt.imshow(img_cvt)
                                    plt.show()





                                    share|improve this answer














                                    To get data from your system to colab try this:



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


                                    Choose the file you want to upload and hit enter and its done.
                                    For example, I have uploaded an image and displayed it using the code below:



                                    import cv2
                                    import numpy as np
                                    from matplotlib import pyplot as plt

                                    img = cv2.imread('image.jpg')
                                    img_cvt = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

                                    plt.imshow(img_cvt)
                                    plt.show()






                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Jul 6 '18 at 8:17









                                    BcK

                                    1,4461616




                                    1,4461616










                                    answered Jul 6 '18 at 8:02









                                    minakshi das

                                    113




                                    113



























                                        draft saved

                                        draft discarded
















































                                        Thanks for contributing an answer to Stack Overflow!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid


                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.

                                        To learn more, see our tips on writing great answers.





                                        Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                        Please pay close attention to the following guidance:


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid


                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.

                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function ()
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f47320052%2fload-local-data-files-to-colaboratory%23new-answer', 'question_page');

                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        Popular posts from this blog

                                        𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

                                        Crossroads (UK TV series)

                                        ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế