我得到了一个结果列表,我想按两个标准对其进行排序。我对 sys 列进行了第一次排序:
systems = {'BzBz_S':0,'BzBz_PD34':1,'MeMe':2}
sorted_results = sorted(results, key = lambda e: (systems[e[0]]))
并传递给 DataFrame
df = pd.DataFrame(sorted_results,columns = ['sys','dis','basis','Energy'])
这给了我以下输出:
,sys,dis,system,basis,Energy
0,BzBz_S,10.0,BzBz_S_10.0,S,0.02562465
1,BzBz_S,3.2,BzBz_S_3.2,S,1.48510297
2,BzBz_S,3.3,BzBz_S_3.3,S,-0.25086498
3,BzBz_S,6.0,BzBz_S_6.0,S,-0.11827975
4,BzBz_S,3.9,BzBz_S_3.9,S,-2.44705244
5,BzBz_PD34,0.4,BzBz_PD34_0.4,PD34,-1.88172312
6,BzBz_PD34,0.2,BzBz_PD34_0.2,PD34,-1.50519034
7,MeMe,5.0,MeMe_5.0,5,-0.12194283
8,MeMe,5.4,MeMe_5.4,5,-0.07556324
除了 sys 之外,我如何创建第二个排序标准来对 dis 列进行排序,以获得这样的最终结果:
,sys,dis,system,basis,Energy
0,BzBz_S,3.2,BzBz_S_3.2,S,1.48510297
1,BzBz_S,3.3,BzBz_S_3.3,S,-0.25086498
2,BzBz_S,3.9,BzBz_S_3.9,S,-2.44705244
3,BzBz_S,6.0,BzBz_S_6.0,S,-0.11827975
4,BzBz_S,10.0,BzBz_S_10.0,S,0.02562465
5,BzBz_PD34,0.2,BzBz_PD34_0.2,PD34,-1.50519034
6,BzBz_PD34,0.4,BzBz_PD34_0.4,PD34,-1.88172312
7,MeMe,5.0,MeMe_5.0,5,-0.12194283
8,MeMe,5.4,MeMe_5.4,5,-0.07556324
幕布斯6054654
相关分类