Python Forum
CSV file escaping characters
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CSV file escaping characters
#1
Hello,

I am trying to do something relatively simple - load a csv file and create a list (or a dataframe). The separator for my file is "|", but the data in my csv file can have all the other characters - ",':, space, etc. Need to ignore them all - but the code that I have messes up when looking through that file. Any help would be appreciated!

#load dataframe from csv
import csv
import pandas as pd

df1 = pd.read_csv('reports/reports_test.csv', delimiter='|')
print(df1)

I am still not able to upload files (do not have five posts yet), so I am posting the sample CSV:

Quote:1|2|3|4
"A zasdff|B sdafasfd,as dfsadf""|C & D are here|D
More data|12, 124, 12|weird delimiters:'no way|stuff
12|><(yes|111|stuff and other stuff


What I need to have is a table/list that look like this:

[Image: final-output.png]

Basically, it should ignore all characters other than "|" when creating each of the fields (theoretically the CSV field can have tabs, newlines, etc as well).

I would appreciate any help!
Reply


Messages In This Thread
CSV file escaping characters - by lokhtar - Dec-09-2019, 06:06 PM
RE: CSV file escaping characters - by buran - Dec-09-2019, 06:35 PM
RE: CSV file escaping characters - by lokhtar - Dec-09-2019, 06:48 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Split Characters As Lines in File quest_ 3 2,531 Dec-28-2020, 09:31 AM
Last Post: quest_
  get two characters, count and print from a .txt file Pleiades 9 3,388 Oct-05-2020, 09:22 AM
Last Post: perfringo
  Introduction to escaping characters in strings Geelong_crazy 1 2,867 Jul-18-2020, 06:58 PM
Last Post: DT2000
  Reading integers from a file; the problem may be the newline characters JRWoodwardMSW 2 1,978 Jul-14-2020, 02:27 AM
Last Post: bowlofred
  Remove escape characters / Unicode characters from string DreamingInsanity 5 13,763 May-15-2020, 01:37 PM
Last Post: snippsat
  Escaping '$' in pymongo raulp2301 0 1,647 Feb-14-2020, 03:48 PM
Last Post: raulp2301
  Replace characters from file in Python 2.7 melmouja 2 2,502 Feb-04-2019, 01:32 PM
Last Post: melmouja
  Problem with Polish characters in xlsx file Mikser 4 3,435 Nov-18-2018, 06:22 PM
Last Post: Gribouillis
  Escaping whitespace and parenthesis in filenames jehoshua 2 9,758 Mar-21-2018, 09:12 AM
Last Post: jehoshua
  need algorithm to strip non-ascii characters from LONG csv file hereathome 3 3,734 Jan-12-2018, 02:04 AM
Last Post: hereathome

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020