Home > Back-end >  Adding a column with no header to a dataframe
Adding a column with no header to a dataframe

Time:11-07

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.

CodePudding user response:

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

CodePudding user response:

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

output:

Index(['Name', 'Age', ''], dtype='object')
  • Related