0

I’ve imported a txt file using read_csv and I need to separate it by multiple parameters. So far all I’ve done is:

‘’’

 df = pd.read_csv(file name, header=None, sep = ‘\n’) 

However along with separating it at the new lines I also need to separate by both a comma and an underscore. How could I do this?

  • Does this answer your question? [import text to pandas with multiple delimiters](https://stackoverflow.com/questions/26551662/import-text-to-pandas-with-multiple-delimiters) – Zaraki Kenpachi Mar 10 '20 at 09:12
  • Can you add an example input line and what the result should be? – tdelaney Mar 10 '20 at 09:17
  • 1
    You are using *fancy* quotes in shown code, you do not show first lines of the csv file to help others to understand the question and you do not show the expected output. Without a [mcve] you could only guess. You should read again [ask]... – Serge Ballesta Mar 10 '20 at 09:18

1 Answers1

4

It depends on format of the data, but You may try:

df = pd.read_csv(filename, header=None, sep='\_|,', engine='python')

When engine is set to "python" you can use regular expressions in sep argument.

ipj
  • 3,488
  • 1
  • 14
  • 18