我需要根据数量和类型
对两列进行排序当前代码段:
import pandas as pd
data1 = pd.read_csv('data/extracted.csv')
data2 = data1.sort(['Result7d'], ascending=True)
data2.to_csv('data/sorted.csv')
对这个Type(x,y,z)进行排序,然后如何使用pandas对Python进行单独的类别排序?
预期结果:
答案 0 :(得分:1)
这可能有效:
import pandas as pd
data1 = pd.read_csv('data/extracted.csv')
#data2 = data1.sort(['Result7d'], ascending=True)
# Use sort_values instead
data1['filenumber'] = data['file'].apply(lambda x: int(x.split('.')[0]))
data2 = data1.sort_values(by=['type', 'filenumber'])
del data2['filenumber']
data2.to_csv('data/sorted.csv')