【发布时间】:2020-09-04 02:14:09
【问题描述】:
当我从指定文件夹导入我的数据文件时,Pandas 数据框会自动对行顺序进行排序,如 A1、A10、A11、...、A2,但我想将其设为 A1、A2、...、A10、A11所以 A2 在 A10、A11 之前。
你知道如何改变行序吗?所有列的行顺序不应仅更改包含 A1、A10、A11、...、A2 的特定列。因此,例如,列 'ID' 和 'Identifier' 的行顺序应该根据 'Loc' 列改变。 此外,实际数据更长,字母更多,直到 Z。
示例代码为:
data = {'ID':['S1', 'S1', 'S1' ,'S1' ,'S2' ,'S3' ,'S3', 'S4', 'Negative', 'Positive', 'Negative',
'S1', 'S1' ,'S2' ,'S2' ,'S2' ,'S3' ,'S4', 'S4', 'Positive', 'Positive', 'Negative'],
'Loc':['A1', 'A10', 'A11' ,'A2' ,'A3' ,'A4' ,'A5', 'A6', 'A7', 'A8', 'A9',
'B1', 'B10', 'B11' ,'B2' ,'B3' ,'B4' ,'B5' ,'B6', 'B7', 'B8', 'B9'],
'Identifier' :['asd01', 'asd02', 'asd04', 'asd05', 'asd06', 'asd07', 'asd08', 'asd09'
,'asd10' ,'asd11' ,'asd13' ,'asd14' ,'asd15', 'asd16', 'asd17', 'asd18',
'asd19', 'asd20', 'asd21', 'asd22', 'asd23', 'asd24']}
感谢您的帮助:)
【问题讨论】:
-
这能回答你的问题吗? sort_values() with key in Python