A TSV file is a simple text file that stores data in a tabular structure. Each record of the table is one line in the TSV file. And each value of a column is separated from the next value using a tab. So, a TSV file is a variation of the CSV file. Please note that in a CSV file, each value is separated from the next value using a comma, while in a TSV file, the values are separated using a tab.
In one of our previous articles, we discussed how to read a CSV file using the pandas.read_csv() function. We can use the same function to read a TSV file. The only difference is we need to specify the sep parameter in the function. In the case of a TSV file, the sep parameter should be “\t”.
We can use the following Python code to read a TSV file using the pandas Python library.
import pandas
df = pandas.read_csv("iris.tsv", sep='\t')
print(df.head())
The output of the above program will be like the following:
sepal_length sepal_width petal_length petal_width species 0 5.1 3.5 1.4 0.2 setosa 1 4.9 3.0 1.4 0.2 setosa 2 4.7 3.2 1.3 0.2 setosa 3 4.6 3.1 1.5 0.2 setosa 4 5.0 3.6 1.4 0.2 setosa








































0 Comments