Skip to content Skip to sidebar Skip to footer

Adding Header To A Dataframe Pandas

i have a DataFrame: Index 1 Dr. Santosh Kumar 0 NaN BHR/ 6681/148/1/134094/2007-08/L 1 NaN B/301, Laxmi Apartment 2 NaN New Chitragupta Nagar, Kankerbagh 3

Solution 1:

Try:

df = pd.DataFrame(
    np.row_stack([df.columns, df.values]),
    columns=['id', 'information']
)

Solution 2:

You can add columns names by parameter names in read_csv if no header file:

df = pd.read_csv(file, names=["id","information"])

If want set columns names by list:

df.columns = ["id","information"]

Post a Comment for "Adding Header To A Dataframe Pandas"