POST POST

OCT
25
2021

Reading a TSV file in Pandas

ORIGINALLY POSTED TO: https://blog.simontimms.com/2021/10/25/pandas-read-tsv

Pretty easy, just use the csv loader with a different record separator

1
data = pd.read_csv('work/data.tsv', sep='\t')

You can tell it explicitly to use the first column as the header

1
data = pd.read_csv('work/data.tsv', sep='\t', header=0)

I also found that it interpreted my first column as an index which I didn't want (it offset all the columns by one)

1
data = pd.read_csv('work/data.tsv', sep='\t', header=0, index_col=False)

Simon Timms

Email Email
Web Web
Twitter Twitter
GitHub GitHub
RSS

Looking for someone else?

You can find the rest of the Western Devs Crew here.

© 2015 Western Devs. All Rights Reserved. Design by Karen Chudobiak, Graphic Designer