1 回答
TA贡献1876条经验 获得超7个赞
获得第一个输出后,您可以执行以下操作以获得最终输出,希望对您有所帮助!
df['sys_cat']=df['sys'].astype('category') #creating a categorical column in the dataframe
d = dict(zip(df.sys_cat,df.sys_cat.cat.codes)) # converting categorical column into codes
# reassigning categories
count=0
for i in d:
d[i]=count
count+=1
df['sys_cat']=df['sys_cat'].map(d).astype(int)
df.sort_values(by=['sys_cat', 'dis'],ascending=[True, True], inplace=True)
df.drop(['sys_cat'], inplace=True, axis=1)
df.reset_index(inplace=True, drop=True)
df
给出:
sys dis system basis Energy
0 BzBz_S 3.2 BzBz_S_3.2 S 1.485103
1 BzBz_S 3.3 BzBz_S_3.3 S -0.250865
2 BzBz_S 3.9 BzBz_S_3.9 S -2.447052
3 BzBz_S 6.0 BzBz_S_6.0 S -0.118280
4 BzBz_S 10.0 BzBz_S_10.0 S 0.025625
5 BzBz_PD34 0.2 BzBz_PD34_0.2 PD34 -1.505190
6 BzBz_PD34 0.4 BzBz_PD34_0.4 PD34 -1.881723
7 MeMe 5.0 MeMe_5.0 5 -0.121943
8 MeMe 5.4 MeMe_5.4 5 -0.075563
添加回答
举报