Skip to content

Commit 5097302

Browse files
authored
DOC: Add to the io documentation of on_bad_lines to alert users of silently skipped lines. (pandas-dev#50311)
* DOC: add to io documentation of on_bad_lines * DOC: add example of silenty skipped line
1 parent 29e287b commit 5097302

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

doc/source/user_guide/io.rst

+15
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,21 @@ The bad line will be a list of strings that was split by the ``sep``:
12551255
12561256
.. versionadded:: 1.4.0
12571257
1258+
Note that the callable function will handle only a line with too many fields.
1259+
Bad lines caused by other errors will be silently skipped.
1260+
1261+
For example:
1262+
1263+
.. code-block:: ipython
1264+
1265+
def bad_lines_func(line):
1266+
print(line)
1267+
1268+
data = 'name,type\nname a,a is of type a\nname b,"b\" is of type b"'
1269+
data
1270+
pd.read_csv(data, on_bad_lines=bad_lines_func, engine="python")
1271+
1272+
The line was not processed in this case, as a "bad line" here is caused by an escape character.
12581273

12591274
You can also use the ``usecols`` parameter to eliminate extraneous column
12601275
data that appear in some lines but not others:

0 commit comments

Comments
 (0)