how to add column names in pandas when read_csv code example
Example 1: Column names reading csv file python
df = pd.read_csv('file.csv', names=['a', 'b', 'c'], header=None)
df.rename(columns = {'a':'A', 'b':'B', 'c':'C'}, inplace = True)
df.to_csv('file.csv')
Example 2: 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)