include header in pandas dataframe code example
Example 1: how to create new header of a dataframe in python
pythonCopy# python 3.x
import pandas as pd
import numpy as np
df = pd.DataFrame(data=np.random.randint(0, 10, (6,4)))
df.columns=["a", "b", "c", "d"]
print(df)
Example 2: how to add header in csv file in python
from pandas import read_csv
df = read_csv('test.csv')
df.columns = ['a', 'b']
df.to_csv('test_2.csv')