Reading Text File in Python

Reading data into an analytical tool is one of the first steps before proceeding to analytics. Some of the common challenges while reading a text file are

  • Knowing Delimiter
  • Presence of Missing  or null values
  • Column values holding date values

In this blog, we will read text file in which values are separated by a tab (reading a tab delimited file).  Here is the sample of the file.

Tab Delimited

Python Code for Reading Tab Delimited File

Output Data Frame

Tab Delimited Output Data Frame

Same Python code above will work even if input Text file has Missing values.

Accessing Column(s) of Data Frame in Python

If we want to access single or multiple columns of the input Data Frame, we can use below Python code.

Access Columns

Leave a Comment