How to add header row to a pandas DataFrame
col_Names=["Sequence", "Start", "End", "Coverage"]
my_CSV_File= pd.read_csv("yourCSVFile.csv",names=col_Names)
having done this, just check it with:
my_CSV_File.head()
Simple And Easy Solution:
import pandas as pd
df = pd.read_csv("path/to/file.txt", sep='\t')
headers = ["Sequence", "Start", "End", "Coverage"]
df.columns = headers
NOTE: Make sure your header length and CSV file header length should not mismatch.
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"])
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"]