0

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.

2
  • Why'd you want to something like that? Can't imagine a usecase where that helps. But if you really need it, what about df[''] = ''. Checking df.columns after that shows, that a new column has been created. Commented Nov 6, 2022 at 14:55
  • I wanted to separate two different blocks of calculations by an empty column. df['']='' indeed worked! Commented Nov 6, 2022 at 17:28

1 Answer 1

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

output:

Index(['Name', 'Age', ''], dtype='object')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.