Skip to content

Commit 1130e03

Browse files
committed
Add Google Colab IO instructions to pandas IO documentation
1 parent a505423 commit 1130e03

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

doc/user_guide/io.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Loading Data into Pandas in Google Colab
2+
Mount Google Drive to Access Files:
3+
This connects your Google Drive storage to the Colab environment so files can be read as if local.
4+
5+
python
6+
from google.colab import drive
7+
drive.mount('/content/drive')
8+
After executing, follow the prompt to authorize access. Your Drive files will appear under /content/drive/.
9+
10+
Locate Your File Path in Drive:
11+
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.
12+
13+
Load the File into a Pandas DataFrame:
14+
Using pandas, read the data with:
15+
16+
python
17+
import pandas as pd
18+
df = pd.read_csv('/content/drive/MyDrive/path_to_file.csv')
19+
df.head()
20+
This works similarly for Excel files (pd.read_excel) or JSON files (pd.read_json).
21+
22+
Alternative: Upload Files Directly from Local to Colab:
23+
If you don't want to use Drive, upload files interactively:
24+
25+
python
26+
from google.colab import files
27+
uploaded = files.upload()
28+
import io
29+
df = pd.read_csv(io.BytesIO(uploaded['filename.csv']))
30+
Replace 'filename.csv' with the uploaded file’s name.
31+
32+
Suggested Addition to Pandas Documentation for Google Colab
33+
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.

0 commit comments

Comments
 (0)