Skip to content

Commit 375a3c8

Browse files
authored
Updated Comparison to Excel documentation with code example of read_excel and to_excel for #38990 (#39242)
1 parent 830b408 commit 375a3c8

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

doc/source/getting_started/comparison/comparison_with_spreadsheets.rst

+21-7
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,6 @@ Both `Excel <https://support.microsoft.com/en-us/office/import-data-from-externa
8989
and :ref:`pandas <10min_tut_02_read_write>` can import data from various sources in various
9090
formats.
9191

92-
Excel files
93-
'''''''''''
94-
95-
Excel opens `various Excel file formats <https://support.microsoft.com/en-us/office/file-formats-that-are-supported-in-excel-0943ff2c-6014-4e8d-aaea-b83d51d46247>`_
96-
by double-clicking them, or using `the Open menu <https://support.microsoft.com/en-us/office/open-files-from-the-file-menu-97f087d8-3136-4485-8e86-c5b12a8c4176>`_.
97-
In pandas, you use :ref:`special methods for reading and writing from/to Excel files <io.excel>`.
98-
9992
CSV
10093
'''
10194

@@ -125,6 +118,27 @@ would be:
125118
# alternatively, read_table is an alias to read_csv with tab delimiter
126119
tips = pd.read_table("tips.csv", header=None)
127120
121+
Excel files
122+
'''''''''''
123+
124+
Excel opens `various Excel file formats <https://support.microsoft.com/en-us/office/file-formats-that-are-supported-in-excel-0943ff2c-6014-4e8d-aaea-b83d51d46247>`_
125+
by double-clicking them, or using `the Open menu <https://support.microsoft.com/en-us/office/open-files-from-the-file-menu-97f087d8-3136-4485-8e86-c5b12a8c4176>`_.
126+
In pandas, you use :ref:`special methods for reading and writing from/to Excel files <io.excel>`.
127+
128+
Let's first :ref:`create a new Excel file <io.excel_writer>` based on the ``tips`` dataframe in the above example:
129+
130+
.. code-block:: python
131+
132+
tips.to_excel("./tips.xlsx")
133+
134+
Should you wish to subsequently access the data in the ``tips.xlsx`` file, you can read it into your module using
135+
136+
.. code-block:: python
137+
138+
tips_df = pd.read_excel("./tips.xlsx", index_col=0)
139+
140+
You have just read in an Excel file using pandas!
141+
128142

129143
Limiting output
130144
~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)