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: unexpected behavior when Loading lines like "\""\t"a" #59222

Open
3 tasks done
hyleepp opened this issue Jul 10, 2024 · 5 comments
Open
3 tasks done

BUG: unexpected behavior when Loading lines like "\""\t"a" #59222

hyleepp opened this issue Jul 10, 2024 · 5 comments
Assignees
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@hyleepp
Copy link

hyleepp commented Jul 10, 2024

Pandas version checks

  • I have checked that this issue has not already been reported.

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

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd

"""
data contains only one line as below
"\""\t"a" (where "\t" is an escape character)
"""

df = pd.read_csv(data, sep='\t', header=None)

Issue Description

image
df will only have one column, which is expected to be two

Expected Behavior

separate it to two lines as we operate in following steps:

line = open(data).read()
line.split("\t") # get two items

Installed Versions

INSTALLED VERSIONS

commit : d9cdd2e
python : 3.11.5.final.0
python-bits : 64
OS : Linux
OS-release : 4.15.0-192-generic
Version : #203-Ubuntu SMP Wed Aug 10 17:40:03 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.2.2
numpy : 1.24.3
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 68.0.0
pip : 23.2.1
Cython : None
pytest : 7.4.0
hypothesis : None
sphinx : 5.0.2
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.3
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.15.0
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.2
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : 2023.4.0
gcsfs : None
matplotlib : 3.7.2
numba : 0.57.1
numexpr : 2.8.4
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 11.0.0
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : 2023.4.0
scipy : 1.11.1
sqlalchemy : None
tables : 3.8.0
tabulate : None
xarray : 2023.6.0
xlrd : None
zstandard : 0.19.0
tzdata : 2023.3
qtpy : None
pyqt5 : None

@hyleepp hyleepp added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 10, 2024
@Anurag-Varma
Copy link
Contributor

Anurag-Varma commented Jul 10, 2024

The data line which you gave is "\""\t"a"

But the image in issue description has different text.

Can you give exactly what should be present, and here does data mean its a path to a .csv file, cause you didn't describe the issue properly ?

@hyleepp
Copy link
Author

hyleepp commented Jul 11, 2024

I’m sorry for my unclear expression.

  1. The actual data is still "\""\t"a" like the below image. The image in the first comment is meant to show that pd does not separated into two elements as expected.
    image
  2. Yes, data means a path to a .csv file that contains the given line.

@Anurag-Varma
Copy link
Contributor

This works when you have the data inside .csv to be in the format of:
"\"" "a"

But fails for "\""\t"a"

I think using the separator \t checks for tab spaces and not for the same exact \t separator

@Anurag-Varma
Copy link
Contributor

@hyleepp

Or else you can use :

import pandas as pd

# Specify the path to your CSV file
file_path = 'test.csv'

# Read the file using tab as the separator
df = pd.read_csv(file_path, delimiter='t', header=None, escapechar='\\')

# Display the dataframe
print(df)

Output:

    0  1
0  "\  a

@Anurag-Varma
Copy link
Contributor

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

2 participants