Andrew Zacharakis
Andrew Zacharakis

Reputation: 350

How can i add multiple column names in pandas DataFrame?

I have a data set of 256 columns and i want to add column names such as : ['N1', 'N2' ... 'N256']. Is there a quick way to do it ?

I have tried something like that :

df.columns = ['S' for x in range(1,257)]

But this code just adds the S in every column. How can i add the indexes also ?

Upvotes: 0

Views: 971

Answers (1)

Andy L.
Andy L.

Reputation: 25239

Is this:

df.columns = ['N'+str(x) for x in range(1,257)]

Upvotes: 1

Related Questions