@@ -1651,6 +1651,86 @@ Writing a formatted string
16511651++++++++++++++++++++++++++
16521652
16531653.. _io.formatting :
1654+ .. _colab-loading :
1655+
1656+ Loading data in Google Colab
1657+ ----------------------------
1658+
1659+ Google Colab is a common environment for pandas users. Below are simple and practical ways to load files into pandas when working in Colab.
1660+
1661+ 1. Upload a local file interactively
1662+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1663+
1664+ Use the Colab upload widget:
1665+
1666+ .. code-block :: python
1667+
1668+ from google.colab import files
1669+ import pandas as pd
1670+
1671+ uploaded = files.upload() # opens a file chooser
1672+ df = pd.read_csv(list (uploaded.keys())[0 ])
1673+
1674+ Notes:
1675+ - Uploaded files are stored temporarily in ``/content/ ``.
1676+ - Only persists for the session.
1677+
1678+ 2. Load files from Google Drive
1679+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1680+
1681+ Mount Google Drive to access stored files:
1682+
1683+ .. code-block :: python
1684+
1685+ from google.colab import drive
1686+ drive.mount(' /content/drive' )
1687+
1688+ import pandas as pd
1689+ df = pd.read_csv(' /content/drive/MyDrive/path/to/file.csv' )
1690+
1691+ 3. Read files directly from URLs or GitHub
1692+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1693+
1694+ If your dataset is online, read it directly:
1695+
1696+ .. code-block :: python
1697+
1698+ import pandas as pd
1699+ df = pd.read_csv(' https://raw.githubusercontent.com/user/repo/main/data.csv' )
1700+
1701+ 4. Use gdown for Google Drive shareable links
1702+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1703+
1704+ For large datasets with Drive share links:
1705+
1706+ .. code-block :: python
1707+
1708+ ! pip install - q gdown
1709+ import gdown
1710+
1711+ url = ' https://drive.google.com/uc?id=FILE_ID'
1712+ gdown.download(url, ' file.csv' , quiet = False )
1713+
1714+ import pandas as pd
1715+ df = pd.read_csv(' file.csv' )
1716+
1717+ 5. Read data from Google Sheets
1718+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1719+
1720+ You can export a Google Sheet as CSV:
1721+
1722+ .. code-block :: python
1723+
1724+ sheet_url = " https://docs.google.com/spreadsheets/d/SHEET_ID/export?format=csv"
1725+ df = pd.read_csv(sheet_url)
1726+
1727+ Quick tips
1728+ ~~~~~~~~~~~~
1729+
1730+ - Use ``df.head() `` to preview data.
1731+ - Prefer GitHub raw links for reproducibility.
1732+ - Files placed in the Colab sidebar appear inside ``/content/ ``.
1733+
16541734
16551735The ``DataFrame `` object has an instance method ``to_string `` which allows control
16561736over the string representation of the object. All arguments are optional:
0 commit comments