Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Skiprows with seperator within rows being skipped #34732

Open
2 of 3 tasks
RobertMouncer opened this issue Jun 12, 2020 · 2 comments
Open
2 of 3 tasks

BUG: Skiprows with seperator within rows being skipped #34732

RobertMouncer opened this issue Jun 12, 2020 · 2 comments
Assignees
Labels
Bug IO CSV read_csv, to_csv

Comments

@RobertMouncer
Copy link

  • I have checked that this issue has not already been reported.
    This may be linked to issue read_csv() - "skiprows" should ignore "comment" #23067

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Code Sample, a copy-pastable example

from io import StringIO
import pandas as pd

text='''# 1: 5
# 3: x
# F: 5.
# ID: 001
# No.: 2
# No.: 4
# Time: 20191216T122109
# Value: ";"
# Time: 4
# Time: ""
# Time ms: ""
# Date: ""
# Time separator: "T"
# J: 1000000
# Silent: false
# mode: true
Timestamp;T;ID;P
16T122109957;0;6;0006'''


pd.read_csv(StringIO(text),skiprows=11,sep=';')
pd.read_csv(StringIO(text),skiprows=16,sep=';')

Problem description

The seperator sep is causing issues when skiprows is requested to skip over rows that contain the seperator. Using 16 (the correct number of rows to skip) causes an EmptyDataError.

Instead the number of rows needs to be worked out by trial and error, in this case the skiprows value needs to be 11.
Using the call below without sep does not cause issues (in terms of skipping the correct number of rows):
pd.read_csv(StringIO(text),skiprows=16)

Expected Output

pd.read_csv('test.TXT',skiprows=16,sep=';')
      Timestamp  T  ID  P
0  16T122109957  0   6  6

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit : None python : 3.8.1.final.0 python-bits : 64 OS : Windows OS-release : 10 machine : AMD64 processor : Intel64 Family 6 Model 142 Stepping 9, GenuineIntel byteorder : little LC_ALL : None LANG : None LOCALE : English_United Kingdom.1252

pandas : 1.0.4
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 20.1.1
setuptools : 41.2.0
Cython : None
pytest : 5.4.2
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.5.0
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.15.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : 4.5.0
matplotlib : 3.2.1
numexpr : 2.7.1
odfpy : None
openpyxl : 3.0.3
pandas_gbq : None
pyarrow : None
pytables : None
pytest : 5.4.2
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : None
xlsxwriter : None
numba : 0.49.1

@RobertMouncer RobertMouncer added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 12, 2020
@RobertMouncer RobertMouncer changed the title BUG: BUG: Skiprows with seperator within rows being skipped Jun 12, 2020
@TomAugspurger
Copy link
Contributor

TomAugspurger commented Jun 12, 2020

Why do you think sep matters? When I replace your ; with , and use the default sep I see the same EmptyDataError.

EDIT: Perhaps I misread your post a bit. But just for clarity, the actual value of sep doesn't matter, just the fact that the separator is in one of the skipped rows.

@TomAugspurger TomAugspurger added IO CSV read_csv, to_csv and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 12, 2020
@TomAugspurger TomAugspurger added this to the Contributions Welcome milestone Jun 12, 2020
@erekevan
Copy link

take

@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO CSV read_csv, to_csv
Projects
None yet
Development

No branches or pull requests

4 participants