Hecar
Hecar

Reputation: 43

Rename row index in Python

How can I do to replace what is marked in red by row 0 (Image 1)? I tried with index_col = 0and header=0 but the result is different from what I want

Image 1

Upvotes: 0

Views: 156

Answers (1)

Christian Sloper
Christian Sloper

Reputation: 7520

Here is an example, column name is taken from row 1

df = pd.DataFrame( {'a': ['b','c']})

df.columns = df.iloc[0].tolist()

This doesn't remove row 0, so if you want to drop that you can go:

df = df.iloc[1:]

Upvotes: 2

Related Questions