pandas怎么逆序输出col2

qq_41524539 2020-10-16 11:18:32
import numpy as np
import pandas as pd
myarray = np.array([[1,2,3],[2,3,4],[3,4,5]])
rowindex = ['row1','row2','row3']
colname = ['col1','col2','col3']
mydataframe = pd.DataFrame(data=myarray,index=rowindex,columns=colname)
...全文
359 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
欢乐的小猪 2020-10-16
  • 打赏
  • 举报
回复
myarray = np.array([[1,2,3],[2,3,4],[3,4,5]])
rowindex = ['row1','row2','row3']
colname = ['col1','col2','col3']
mydataframe = pd.DataFrame(data=myarray,index=rowindex,columns=colname)
print(mydataframe['col2'][::-1])
zengxj100 2020-10-16
  • 打赏
  • 举报
回复
import numpy as np import pandas as pd myarray = np.array([[1,2,3],[2,3,4],[3,4,5]]) rowindex = ['row1','row2','row3'] colname = ['col1','col2','col3'] mydataframe = pd.DataFrame(data=myarray,index=rowindex,columns=colname) # print(mydataframe) d=sorted(mydataframe['col2'],reverse=True) print(d) 运行结果: [4, 3, 2]

37,717

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧