更新时间:2023-02-20 07:52:54
只需添加到现有解决方案中,即可使用 inflect
创建动态字典
Just adding in to the existing solutions , you can use inflect
to create dynamic dictionary
import inflect
p = inflect.engine()
df['Name'] += df.groupby('Name').cumcount().add(1).map(p.ordinal).radd('_')
print(df)
Name Age
0 Tom_1st 20
1 Tom_2nd 21
2 Jack_1st 19
3 Terry_1st 18