0

I am reading a file that has \n as a new line character. But when I read it using pandas, it appears as \\n. How can I avoid this?

I tried both pandas and python csv but nothing worked

DYZ
  • 55,249
  • 10
  • 64
  • 93
  • Please *show* what you are doing and what result you are getting. Copy relevant code/commands/data and paste to your question *as text*. – n. m. could be an AI Jan 24 '23 at 18:15
  • It's not changing, that's just the way Python shows it. – Mark Ransom Jan 24 '23 at 18:16
  • If the linked duplicates _aren't_ on-point, please [edit] your question to include enough technical details to clearly distinguish your question from the preexisting ones, and @-notify me when that edit is complete. – Charles Duffy Jan 24 '23 at 18:27

1 Answers1

0

in pandas, you can set lineterminator to '\n' and that should work. Alternatively, you can use the csv module in python to read your csv file as follows :

import csv
with open(filepath, newline='', encoding='utf-8') as f:
    reader = csv.reader(f, delimiter='\n')
    for row in reader:
        print(row)
Haresh K
  • 11
  • 1