Search code examples
pythonpandaspandas-groupbyseriesreindex

How to reindex a spesific column in Pandas?


gd = df.groupby(['subID'])['Accuracy'].std()

print(gd)

subID
4       0.810423
5       0.841364
6       0.881007
8       0.763175
9       0.760102
10      0.905283
12      0.928358
14      0.779291
15      0.912377
1018    0.926683

It displays like this and I assume it is a Series, not a DataFrame. I want to change the last index from 1018 to 13.


Solution

  • Use rename with dictionary, because first column here is index of Series:

    gd = gd.rename({1018:13})
    

    Working like:

    gd = gd.rename(index={1018:13})