saleh
saleh

Reputation: 405

apply anonymous function on the index of dataFrame

I want to apply a anonymous function (using .apply()) like lambda x: x + 1 on indexes of dataframes (not on the columns) how can I do it?

Upvotes: 1

Views: 275

Answers (1)

MaxU - stand with Ukraine
MaxU - stand with Ukraine

Reputation: 210872

One way would be:

df.set_index(df.index + 1)

another:

df.assign(index=lambda x: x.index+1).set_index('index')

Upvotes: 3

Related Questions