From 1130e030ecedd38c5d02f0ddb52809d985d74497 Mon Sep 17 00:00:00 2001 From: harsha08-2k6 <2400030361@kluniversity.in> Date: Thu, 13 Nov 2025 11:56:37 +0530 Subject: [PATCH] Add Google Colab IO instructions to pandas IO documentation --- doc/user_guide/io.rst | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 doc/user_guide/io.rst diff --git a/doc/user_guide/io.rst b/doc/user_guide/io.rst new file mode 100644 index 0000000000000..875039fefd5ac --- /dev/null +++ b/doc/user_guide/io.rst @@ -0,0 +1,33 @@ +Loading Data into Pandas in Google Colab +Mount Google Drive to Access Files: +This connects your Google Drive storage to the Colab environment so files can be read as if local. + +python +from google.colab import drive +drive.mount('/content/drive') +After executing, follow the prompt to authorize access. Your Drive files will appear under /content/drive/. + +Locate Your File Path in Drive: +Use the file explorer pane in Colab to navigate to your file, right-click it, and select "Copy path." The path will be something like /content/drive/MyDrive/path_to_file.csv. + +Load the File into a Pandas DataFrame: +Using pandas, read the data with: + +python +import pandas as pd +df = pd.read_csv('/content/drive/MyDrive/path_to_file.csv') +df.head() +This works similarly for Excel files (pd.read_excel) or JSON files (pd.read_json). + +Alternative: Upload Files Directly from Local to Colab: +If you don't want to use Drive, upload files interactively: + +python +from google.colab import files +uploaded = files.upload() +import io +df = pd.read_csv(io.BytesIO(uploaded['filename.csv'])) +Replace 'filename.csv' with the uploaded file’s name. + +Suggested Addition to Pandas Documentation for Google Colab +A dedicated section on the IO page explaining this process would be useful for users running pandas in Colab, covering Drive mounting, direct uploading, and basic file reading commands.