Skip to content

Commit 790839c

Browse files
committed
google colab docs for pandas has been added
1 parent ecf28e5 commit 790839c

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

doc/source/user_guide/io.rst

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,73 @@ The pandas I/O API is a set of top level ``reader`` functions accessed like
4343
For examples that use the ``StringIO`` class, make sure you import it
4444
with ``from io import StringIO`` for Python 3.
4545

46+
47+
Loading data in Google Colab
48+
----------------------------
49+
50+
Google Colab is a hosted Jupyter notebook environment that is commonly
51+
used with pandas. Since Colab runs on a remote machine, loading data
52+
differs slightly from working in a local environment.
53+
54+
This section describes the most common ways to load data into pandas
55+
when using Google Colab.
56+
57+
Upload files from your local computer
58+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
59+
60+
Files can be uploaded directly from your local machine using Colab's
61+
``files.upload`` helper. Uploaded files are placed in the current
62+
working directory (``/content``).
63+
64+
.. code-block:: python
65+
66+
from google.colab import files
67+
uploaded = files.upload()
68+
69+
import pandas as pd
70+
df = pd.read_csv("data.csv")
71+
df.head()
72+
73+
.. note::
74+
75+
Files uploaded this way are stored temporarily and are removed when
76+
the Colab runtime is reset.
77+
78+
Load files from Google Drive
79+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
80+
81+
Google Drive can be mounted in Colab to provide persistent storage
82+
across sessions.
83+
84+
.. code-block:: python
85+
86+
from google.colab import drive
87+
drive.mount("/content/drive")
88+
89+
import pandas as pd
90+
df = pd.read_csv("/content/drive/MyDrive/data.csv")
91+
df.head()
92+
93+
.. note::
94+
95+
Files stored in Google Drive persist across Colab sessions. The drive
96+
must be mounted before files can be accessed.
97+
98+
Load data from a URL
99+
~~~~~~~~~~~~~~~~~~~
100+
101+
Pandas can also load data directly from a URL without uploading files
102+
or mounting external storage.
103+
104+
.. code-block:: python
105+
106+
import pandas as pd
107+
108+
url = "https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv"
109+
df = pd.read_csv(url)
110+
df.head()
111+
112+
46113
.. _io.read_csv_table:
47114

48115
CSV & text files

0 commit comments

Comments
 (0)