0

I have a separated file where delimiter is 3-symbols: '*'

pd.read_csv(file, delimiter="'*'")

Raises an error:

"delimiter" must be a 1-character string

As some lines can contain *-symbol, I can't use star without quotes as a separator. That's why I don't think stripping lines can help here.

Is it possible to parse separated files with separators that contains more than 1 symbol?

5
  • You could use regular expressions to replace every instance of '*' with a comma or other single character separator before reading the file with pandas. Commented Feb 10, 2020 at 10:52
  • I was also thinking about this, but it's not exactly what I want, because "comma" or other single characters can be also part of the file. Then I'll have another problem, that some rows will be wrongly parsed (more elements than expected, etc.) because this character exists in this row. Commented Feb 10, 2020 at 10:57
  • The usual way to avoid that is to have a quote character for strings (you could add one with regex too I think). What about using tab as the separator? Commented Feb 10, 2020 at 11:01
  • Does this answer your question? Use Multiple Character Delimiter in Python Pandas read_csv Commented Feb 10, 2020 at 11:04
  • @Andy_101 this is not helping for me, because I know that I have both "'" and "*" symbols. From the answer mentioned above it looks like "or" operator. Commented Feb 10, 2020 at 11:20

1 Answer 1

0

for input

as'*'asfg'*'agga
as'*'asfg'*'agga
as'*'asfg'*'agga

outputs

>>> pd.read_csv("testing.csv",sep="\'\*\'")
   as  asfg  agga
0  as  asfg  agga
1  as  asfg  agga

this should solve your issue.

Sign up to request clarification or add additional context in comments.

3 Comments

It raises the same error - "delimiter" must be a 1-character string
which python or pandas version are you using because for me this is working perfectly.
try sharing some of your input data maybe.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.