Adding a column with no header to a dataframe

Question:

How can I add an empty column to my dataframe without introducing a header to it?

I am using pandas to work on a dataframe where I need to add an empty column without any header. I know that by using

df["New_Column_Name"] = "" 

(where df is my dataframe) would add an empty column to the df. But, in my case I don’t want that "New_Column_Name" there.
Thanks.

Asked By: mangalam

||

Answers:

data = {'Name': ['Rob', 'Bob', 'Tob'],
        'Age': [20, 21, 19]}
df = pd.DataFrame(data)
df[''] = ''
print(df.columns)

output:

Index(['Name', 'Age', ''], dtype='object')
Answered By: ADL

I strongly suggest you create some dummy name for column header. Creating a dataframe without headers is not a good option for manipulating afterward

Answered By: Quoc
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.