How to use split In Python
The very simple way to read data from TSV File in Python is using split(). We can read a given TSV file and store its data into a list.
Syntax:
with open("filename.tsv") as file: for line in file: l=line.split('\t')
Example: Program Using split()
Python3
# Simple Way to Read TSV Files in Python using split ans = [] # open .tsv file with open ( "GeekforGeeks.tsv" ) as f: # Read data line by line for line in f: # split data by tab # store it in list l = line.split( '\t' ) # append list to ans ans.append(l) # print data line by line for i in ans: print (i) |
Output:
Simple Ways to Read TSV Files in Python
In this article, we will discuss how to read TSV files in Python.
Input Data:
We will be using the same input file in all various implementation methods to see the output. Below is the input file from which we will read data.