python - How to load a tsv file into a Pandas DataFrame?

ID : 20108

viewed : 22

Tags : pythonpandascsvpython

Top 5 Answer for python - How to load a tsv file into a Pandas DataFrame?

vote vote

90

The .read_csv function does what you want:

pd.read_csv('c:/~/trainSetRel3.txt', sep='\t') 

If you have a header, you can pass header=0.

pd.read_csv('c:/~/trainSetRel3.txt', sep='\t', header=0) 

Note: Prior 17.0, pd.DataFrame.from_csv was used (it is now deprecated and the .from_csv documentation link redirects to the page for pd.read_csv).

vote vote

85

As of 17.0 from_csv is discouraged.

Use pd.read_csv(fpath, sep='\t') or pd.read_table(fpath).

vote vote

73

Use pandas.read_table(filepath). The default separator is tab.

vote vote

70

Try this

df = pd.read_csv("rating-data.tsv",sep='\t') df.head() 

enter image description here

You actually need to fix the sep parameter.

vote vote

51

open file, save as .csv and then apply

df = pd.read_csv('apps.csv', sep='\t') 

for any other format also, just change the sep tag

Top 3 video Explaining python - How to load a tsv file into a Pandas DataFrame?

Related QUESTION?