Skip to content

Commit 1663fde

Browse files
committed
DOC: add new sections na_values, infinity to read_csv docs
1 parent 6ea8e1b commit 1663fde

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

doc/source/io.rst

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,53 @@ The ``thousands`` keyword allows integers to be parsed correctly
546546
547547
os.remove('tmp.csv')
548548
549+
.. _io.na_values:
550+
551+
NA Values
552+
~~~~~~~~~
553+
554+
To control which values are parsed as missing values (which are signified by ``NaN``), specifiy a
555+
list of strings in ``na_values``. If you specify a number (a ``float``, like ``5.0`` or an ``integer`` like ``5``),
556+
the corresponding equivalent values will also imply a missing value (in this case effectively
557+
``[5.0,5]`` are recognized as ``NaN``.
558+
559+
To completely override the default values that are recognized as missing, specify ``keep_default_na=False``.
560+
The default ``NaN`` recognized values are ``['-1.#IND', '1.#QNAN', '1.#IND', '-1.#QNAN', '#N/A N/A', 'NA',
561+
'#NA', 'NULL', 'NaN', 'nan']``.
562+
563+
.. code-block:: python
564+
565+
read_csv(path, na_values=[5])
566+
567+
the default values, in addition to ``5`` , ``5.0`` when interpreted as numbers are recognized as ``NaN``
568+
569+
.. code-block:: python
570+
571+
read_csv(path, keep_default_na=False, na_values=[""])
572+
573+
only an empty field will be ``NaN``
574+
575+
.. code-block:: python
576+
577+
read_csv(path, keep_default_na=False, na_values=["NA", "0"])
578+
579+
only ``NA`` and ``0`` as strings are ``NaN``
580+
581+
.. code-block:: python
582+
583+
read_csv(path, na_values=["Nope"])
584+
585+
the default values, in addition to the string ``"Nope"`` are recognized as ``NaN``
586+
587+
.. _io.infinity:
588+
589+
Infinity
590+
~~~~~~~~
591+
592+
``inf`` like values will be parsed as ``np.inf`` (positive infinity), and ``-inf`` as ``-np.inf`` (negative infinity).
593+
These will ignore the case of the value, meaning ``Inf``, will also be parsed as ``np.inf``.
594+
595+
549596
.. _io.comments:
550597

551598
Comments

doc/source/v0.13.0.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ Bug Fixes
6666

6767
- Suppressed DeprecationWarning associated with internal calls issued by repr() (:issue:`4391`)
6868

69-
- Fixed passing ``keep_default_na=False`` when ``na_values=None`` (:issue:`4318`)
70-
7169
See the :ref:`full release notes
7270
<release>` or issue tracker
7371
on GitHub for a complete list.

0 commit comments

Comments
 (0)