开发者

pandas按某列降序的实现

升序

import pandas as pd
import numpy as np

data = np.random.randint(low=2,high=10,size=(5,3))
data2 = np.random.randint(low=2,high=10,size=(5,3))

df1 = pd.DataFrame(data,columns=["a","b","c"开发者_Python教程],index=range(5))  
df2 = pd.DataFrame编程(data2,columns=["a","b","c"],index=range(5))

df1 = df1.sort_values(编程客栈by=['a','b'])
print(df1)

运行结果:

pandas按某列降序的实现

降序

import pandas as pd
import numpy as np

data = np.random.randint(low=2,high=10,size=(5,3))
data2 = np.random.rand编程int(low=2,high=10,size=(5,3))

df1 = pd.DataFrame(data,columns=["a","b","c"],index=range(5))  
df2 = pd.DataFrame(data2,columns=["a","b","c"],index=range(5))

df1 = df1.sojsrt_values(by=['a','b'], ascending=[False, False])
print(df1)

运行结果:

pandas按某列降序的实现

PS: 先按a降序,再按b降序

到此这篇关于pandas按某列降序的实现的文章就介绍到编程客栈这了,更多相关pandas 列降序内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新开发

开发排行榜