How to Read a Text File in Pandas?

Spread the love

Problem –

You want to read a text file in pandas.

Solution –

To read a text file in pandas we use the read_csv method along with the delimiter that is used in the file. Your file could have other delimiter like tab ( ‘\t’ ) , commas ( ‘,’ ), space ( ‘ ‘ ) etc. Here we have semicolon so we used that.

import pandas as pd

df = pd.read_csv('salary.txt', delimiter=';')
df.head()

Rating: 1 out of 5.

Leave a Reply