How to write Pandas DataFrame as TSV using Python?
In this article, we will discuss how to write pandas dataframe as TSV using Python.
Let’s start by creating a data frame. It can be done by importing an existing file, but for simplicity, we will create our own.
name age 0 a 24 1 b 65 2 c 39 3 d 18
Now, let’s export this as a TSV file. We can use to_csv method from pandas for this.
Syntax: df.to_csv(” file.tsv”, sep = “”)
Here, sep defines what is the separator which separates the data entries in the file. In this case, we define it as a tabspace (‘\t’). It will create a .csv file by default if the separator is not defined.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course