Predictive Hacks

How to Add Multiple Headers in Pandas Dataframes

df=pd.DataFrame([[1,2,3,4],[6,7,8,9]])

df

To add multiple headers, we need to create a list of lists of headers and use it to rename the columns of the dataframe.

header=[['A','A','B','B'],
        ['A','B','C','D']]

df.columns=header

df

Share This Post

Share on facebook
Share on linkedin
Share on twitter
Share on email

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore

Python

Image Captioning with HuggingFace

Image captioning with AI is a fascinating application of artificial intelligence (AI) that involves generating textual descriptions for images automatically.