A delimiter, or field separator, marks the boundary between adjacent fields in a structured text record. In CSV data, commas separate fields by default, but files may use tabs, colons, or other characters. pandas exposes this choice through the sep argument of read_csv and to_csv. section 3.0
Parsing a colon-delimited passwd file
A Unix passwd file is a useful variation on ordinary CSV: its fields are separated by colons rather than commas. Parse it with read_csv('linux-etc-passwd.txt', sep=':', comment='#', header=None, names=['username', 'password', 'userid', 'groupid', 'name', 'homedir', 'shell'], index_col='username'). The separator makes each colon-delimited value become a separate data-frame column; comment and header options handle the file's other irregularities. section 3.12 section 3.13
When importing delimited text, check these related assumptions:
- Use sep=',' for ordinary comma-separated data or replace the comma with the file's actual separator, such as sep='\t' or sep=':'. section 3.0 section 3.13
- Treat the separator as one part of parsing: headers, comments, blank lines, and index columns can also determine whether the resulting data frame is usable. section 3.13
pd.read_csv('mydata.csv', #1
sep='\t', #2
index_col='w', #3
usecols=['w', 'x', 'z'], #4
header=0) #5
Inspect a compact read_csv call that combines sep with index, column-selection, and header arguments. section 3.0










