浅谈Series和DataFrame中的sort_index方法

yipeiwu_com6年前Python基础

Series 的 sort_index(ascending=True) 方法可以对 index 进行排序操作,ascending 参数用于控制升序或降序,默认为升序。

若要按值对 Series 进行排序,当使用 .order(na_last=True, ascending=True, kind='mergesort') 方法,任何缺失值默认都会被放到 Series 的末尾。

在 DataFrame 上,.sort_index(axis=0, by=None, ascending=True) 方法多了一个轴向的选择参数与一个 by 参数,by 参数的作用是针对某一(些)列进行排序(不能对行使用 by 参数)。

注意在使用sort_index对DataFrame进行排序的时候,不能直接对index和columns都含有的字段进行排序,会报错。

以上这篇浅谈Series和DataFrame中的sort_index方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python 获取微信好友列表的方法(微信web)

如下所示: import urllib import urllib2 import os import time import re import cookielib im...

如何基于python操作json文件获取内容

这篇文章主要介绍了如何基于python操作json文件获取内容,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 写case时,将case...

Python实现简单多线程任务队列

最近我在用梯度下降算法绘制神经网络的数据时,遇到了一些算法性能的问题。梯度下降算法的代码如下(伪代码): def gradient_descent(): # the gradie...

Python GUI布局尺寸适配方法

如下所示: #coding=utf-8 #布局自定义尺寸 from tkinter import * class App: def __init__(self,master...

python遍历文件夹并删除特定格式文件的示例

复制代码 代码如下:#!/usr/bin/python# -*- coding: utf-8 -*- import os def del_files(path):  ...