How to make First Column as Index in Pandas

What are Pandas in Python?

Pandas is an open-source exploratory data analytics library written for empowering Python to analyze and leverage the data and make good decisions to draw great insights out of it.

It provides very rich and robust data operations, and the general calculations and functions that we can do in Microsoft Excel are written in Python programming language.

There are two main Data Structures in Pandas library that Python Programming Language works with

  1. Series in Pandas Data Structure– it is a one-dimensional array with an indexing feature to navigate, and it stores a single column of data or a row of data in a data frame of the module.
  2. Data frame in Pandas Data Structure – it is simply just like an excel-like tabular spreadsheet that represents rows, and those rows each of which may contain one or multiple columns in the module.

A one-dimensional array which is labelled is capable of holding any type of data series, and a two-dimensional array is a labelled structure with columns of potentially different types of data -data frame.

To Set the First Column as an Index in Pandas Library Python

If the users are aware the column names of their module before the file is read, it is better if they pass the list using the names parameter of read_table in the module.

Code:

With open('file.txt') as f:
Table = pd.read_table(f, sep='-', index_col=0, header = None, names=['A','B','C'],
                       Lineterminator='\n')

Output: 

A    B     C
Id1   a1   b1  c1
Id2   a2   b2   c2