Pandas version checks
-
[X] I have checked that this issue has not already been reported.
-
[X] I have confirmed this bug exists on the latest version of pandas.
-
[X] 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
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
Comment From: Anurag-Varma
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 ?
Comment From: hyleepp
I’m sorry for my unclear expression.
- 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. - Yes, data means a path to a .csv file that contains the given line.
Comment From: Anurag-Varma
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
Comment From: Anurag-Varma
@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
Comment From: Anurag-Varma
take
Comment From: Anurag-Varma
Hi @hyleepp if the issue is solved can you close the issue ?
If u think there is a bug, you can keep it open.
Thanks