Python Practice › Pandas Programs › Program 51

Write a tab-separated file

EasyPandas Programs · 51 of 95

Write a pandas program to write a DataFrame to a CSV file with a tab separator.

Advertisement
Output
name	age	salary
Alex	30	50000
John	27	65000

Approach

  1. to_csv(sep="\t").

Solution

Python
import pandas as pddf = pd.DataFrame({"name": ["Alex", "John"], "age": [30, 27], "salary": [50000, 65000]})df.to_csv("people.tsv", sep="\t", index=False)print(open("people.tsv").read())
Output
name	age	salary
Alex	30	50000
John	27	65000
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More pandas programs

← All 95 Pandas Programs