From b71d0e337de5edaf63f37b4e5d2893f42ceb1921 Mon Sep 17 00:00:00 2001 From: phofl Date: Sun, 28 Nov 2021 12:41:31 +0100 Subject: [PATCH] DOC: Clarify how to keep lines with too many fields --- doc/source/user_guide/io.rst | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/doc/source/user_guide/io.rst b/doc/source/user_guide/io.rst index bb7be92bd993b..e21dac65c4c4c 100644 --- a/doc/source/user_guide/io.rst +++ b/doc/source/user_guide/io.rst @@ -1306,6 +1306,20 @@ data that appear in some lines but not others: 1 4 5 6 2 8 9 10 +In case you want to keep all data including the lines with too many fields, you can +specify a sufficient number of ``names``. This ensures that lines with not enough +fields are filled with ``NaN``. + +.. code-block:: ipython + + In [31]: pd.read_csv(StringIO(data), names=['a', 'b', 'c', 'd']) + + Out[31]: + a b c d + 0 1 2 3 NaN + 1 4 5 6 7 + 2 8 9 10 NaN + .. _io.dialect: Dialect