close

How to add header row to a pandas DataFrame

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to add header row to a pandas DataFrame in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to add header row to a pandas DataFrame?

  1. How to add header row to a pandas DataFrame?

    Alternatively you could read you csv with header=None and then add it with df.columns:
    Cov = pd.read_csv("path/to/file.txt", sep='\t', header=None) Cov.columns = ["Sequence", "Start", "End", "Coverage"]

  2. add header row to a pandas DataFrame

    Alternatively you could read you csv with header=None and then add it with df.columns:
    Cov = pd.read_csv("path/to/file.txt", sep='\t', header=None) Cov.columns = ["Sequence", "Start", "End", "Coverage"]

Method 1

You can use names directly in the read_csv

names : array-like, default None List of column names to use. If file contains no header row, then you should explicitly pass header=None

Cov = pd.read_csv("path/to/file.txt", 
                  sep='\t', 
                  names=["Sequence", "Start", "End", "Coverage"])

Method 2

Alternatively you could read you csv with header=None and then add it with df.columns:

Cov = pd.read_csv("path/to/file.txt", sep='\t', header=None)
Cov.columns = ["Sequence", "Start", "End", "Coverage"]

Conclusion

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read