'how to change the first column name in dataframe

      first        second           third           fourth
1       9             2               0                7
0       4             3               2                1
3       4             0               4               -1
2       0             1               8               -5
       first       second           third           fourth
0       7             11              1               -7
3       2             5               5               -12
1       2             4               3                1
2      -3             7              -1                7

I have this data set in the panda data fame. I wonder about how can I change the value of the first column?(this is 2 different sets of data)

i.e. list = ['abc','def','ghi','xyz'] i want this to replace those 0 1 2 3 in the first column in order respectively. I got something like this but it does not seem to work with multiple sets of data only work for one

for i in range(4):
   df.rename(index={i: list[i]})

this is the error I got incase it may helps TypeError: unhashable type: 'list'

P.S. I already sorted the data descending using the 'first' column so the index 0 1 2 3 is mixed up

my expected out put would be something like

first        second           third           fourth
def       9             2               0                7
abc       4             3               2                1
xyz       4             0               4               -1
ghi       0             1               8               -5
       first       second           third           fourth
abc       7             11              1               -7
xyz       2             5               5               -12
def       2             4               3                1
ghi      -3             7              -1                7


Solution 1:[1]

Use map

d = dict(zip([0,1,2,3],['abc','def','ghi','xyz']))
df.index= df.index.map(d)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 BENY