0

"WANT Keep DATA order originally " : That's my orginality of Question

I have a Dataframe like this :

Original df :

     name   unit   col1   col2
    ----[0]  01    1.72   3.87
    ----[0]  02    1.34   4.55
    ----[0]  03    6.25   6.55
    ----[0]  01    7.94   7.22
    ----[0]  02    5.07   5.10
    ----[0]  03    3.39   2.66
    ----[1]  01    4.62   6.27
    ----[1]  02    5.34   5.45
    ----[1]  03    9.95   2.95
    ----[1]  01    3.94   1.82
    ----[1]  02    2.47   3.50
    ----[1]  03    2.39   0.76
    ...     ...     ...    ... 
    ----[6]  01    0.34   0.15
    ----[6]  02    6.25   6.25
    ----[6]  03    3.65   5.65
    ----[6]  01    1.74   4.32
    ----[6]  02    2.67   6.52
    ----[6]  03    8.99   5.76

And I manufactured this orginal one

df = df.sort_values(by=["name"], ascending=False)
df['unit'] = 'unit' +df.groupby('name').cumcount().add(1).astype(str).str.zfill(2)

I wanted the dataframe is ordered in original order. But!! after the 2 code the dataframe order is rearranged randomly... So, now i want to order the Dataframe['unit'] in original sequence, just chnaging unit name.

Want one:

     name   unit   col1   col2
    ----[0] unit01    1.72   3.87
    ----[0] unit02    1.34   4.55
    ----[0] unit03    6.25   6.55
    ----[0] unit04    7.94   7.22
    ----[0] unit05    5.07   5.10
    ----[0] unit06    3.39   2.66
       ...   ...   ...     ...
888Seeme
  • 47
  • 5

0 Answers0