.. _10min_tut_02_read_write: {{ header }} .. ipython:: python import pandas as pd .. raw:: html
Data used for this tutorial:
How do I read and write tabular data? ===================================== .. image:: ../../_static/schemas/02_io_readwrite.svg :align: center .. raw:: html Make sure to always have a check on the data after reading in the data. When displaying a ``DataFrame``, the first and last 5 rows will be shown by default: .. ipython:: python titanic .. raw:: html .. note:: Interested in the last N rows instead? pandas also provides a :meth:`~DataFrame.tail` method. For example, ``titanic.tail(10)`` will return the last 10 rows of the DataFrame. A check on how pandas interpreted each of the column data types can be done by requesting the pandas ``dtypes`` attribute: .. ipython:: python titanic.dtypes For each of the columns, the used data type is enlisted. The data types in this ``DataFrame`` are integers (``int64``), floats (``float64``) and strings (``object``). .. note:: When asking for the ``dtypes``, no parentheses ``()`` are used! ``dtypes`` is an attribute of a ``DataFrame`` and ``Series``. Attributes of a ``DataFrame`` or ``Series`` do not need ``()``. Attributes represent a characteristic of a ``DataFrame``/``Series``, whereas methods (which require parentheses ``()``) *do* something with the ``DataFrame``/``Series`` as introduced in the :ref:`first tutorial <10min_tut_01_tableoriented>`. .. raw:: html The equivalent read function :meth:`~DataFrame.read_excel` will reload the data to a ``DataFrame``: .. ipython:: python titanic = pd.read_excel("titanic.xlsx", sheet_name="passengers") .. ipython:: python titanic.head() .. ipython:: python :suppress: import os os.remove("titanic.xlsx") .. raw:: html .. raw:: html

REMEMBER

- Getting data in to pandas from many different file formats or data sources is supported by ``read_*`` functions. - Exporting data out of pandas is provided by different ``to_*`` methods. - The ``head``/``tail``/``info`` methods and the ``dtypes`` attribute are convenient for a first check. .. raw:: html
.. raw:: html
To user guide For a complete overview of the input and output possibilities from and to pandas, see the user guide section about :ref:`reader and writer functions `. .. raw:: html