Alex Lenail
Alex Lenail

Reputation: 14440

Pandas overwrite column names by position

I'm reading in a csv, and I'd like to overwrite the first two column names.

Any ideas for how to do this sensibly in pandas?

Upvotes: 3

Views: 2630

Answers (1)

MaxU - stand with Ukraine
MaxU - stand with Ukraine

Reputation: 210832

Try this:

df.columns = ['name 1', 'name 2'] + df.columns[2:].tolist()

Upvotes: 7

Related Questions