I am trying to read some data which may sometimes have erroneous and bad rows, so as always I passed error_bad_lines=False
but the console keeps throwing the deprecation warning on every run. Why is this feature deprecated and is there any other alternative for skipping bad lines?
Asked
Active
Viewed 1.4k times
14

smci
- 32,567
- 20
- 113
- 146

Atharva Katre
- 457
- 1
- 6
- 17
-
Which function do you use? `read_csv`? – Corralien Oct 10 '21 at 09:32
-
Yes, sorry forgot to mention that. – Atharva Katre Oct 10 '21 at 11:13
1 Answers
36
Read the documentation:
Deprecated since version 1.3.0: The on_bad_lines parameter should be used instead to specify behavior upon encountering a bad line instead.
So, replace:
df = pd.read_csv(..., error_bad_lines=False)
with:
df = pd.read_csv(..., on_bad_lines='skip')

Sunderam Dubey
- 1
- 11
- 20
- 40

Corralien
- 109,409
- 8
- 28
- 52
-
Thanks for the answer. Just to make it even more clear, if you use `error_bad_lines` and `warn_bad_lines`, both should be replaced by `on_bad_lines`. – ruhanbidart Jul 08 '22 at 18:58
-
2@ruhanbidart. Right you can replace `error_bad_lines=True` by `on_bad_lines='error'` and `warn_bad_lines=True` by `on_bad_lines='warn'` – Corralien Jul 08 '22 at 21:49
-
1