# custom delimiter for dat file

I've a dat file in the following format which I'm trying to load using pandas.

28::Persuasion (1995)::Romance
29::City of Lost Children, The (1995)::Adventure|Sci-Fi
30::Shanghai Triad (Yao a yao yao dao waipo qiao) (1995)::Drama
31::Dangerous Minds (1995)::Drama
32::Twelve Monkeys (1995)::Drama|Sci-Fi
34::Babe (1995)::Children's|Comedy|Drama


Code

movies = pd.read_csv('movies.dat')


I'm getting this error

ParserError: Error tokenizing data. C error: Expected 1 fields in line 11, saw 2


Line 11:

11::American President, The (1995)::Comedy|Drama|Romance


I understand that it's because of the comma. One option I found is to skip these lines, which I don't want to. Is it possible to set newline as the delimiter here? Any help will be truly appreciated.

• What is the command you are using? – David Masip May 6 '18 at 7:46
• Do you want to separate by | or by ::? – David Masip May 6 '18 at 7:55
• @DavidMasip :: should be fine. later i can sort out the genre which are separated by | – Van Peer May 6 '18 at 7:57

You have to tell

pd.read_csv


the separator that you want to use by doing:

pd.read_csv('movies.dat', sep = '::')


This should work.

• this worked movies = pd.read_csv('movies.dat', sep='::', engine='python'). – Van Peer May 6 '18 at 8:02