zoukankan      html  css  js  c++  java
  • DataFrame 索引和复合索引

    前面按照多个条件进行分组产生的索引是复合索引

    一、索引

    # a、获取index
    df.index
    # b、指定index
    df.index = []
    # c、重新设置index
    df.reindex(['a', 'b', 'c'])  
    # 注意:一般不用
    # d、指定某一列作为index
    df2 = df1.set_index('O', drop=False)
    # drop默认是True,丢弃指定的那一列
    # e、指定某多列作为index
    df2 = df1.set_index(['M', 'O'], drop=False)
    # f、对index进行去重操作 
    df1.set_index('O', drop=False).index.unique()

    二、复合索引

    1、基础知识

    # a、复合索引
    df.set_index(['c', 'd'])
    # b、交换复合索引的顺序
    df.swaplevel()

    2、Series

    # a、取Series
    df.set_index(['c', 'd'])['a']       # Series
    # b、取具体值
    df.set_index(['c', 'd'])['a']['c列的索引值']['d列的索引值']
    #
    df.set_index(['c', 'd'])['a']['c列的索引值', 'd列的索引值']

    3、DataFrame

    # a、取DataFrame
    df.set_index(['c', 'd'])[['a']]
    # b、取具体值
    df.set_index(['c', 'd'])[['a']].loc['c列的索引值'].loc['d列的索引值']
  • 相关阅读:
    Mybatis 持久层框架
    spring beans文件
    java_抽象类&抽象方法
    java——类
    python 安装 HTMLtestRunner
    pychram永久激活
    unittest单元测试框架
    pandas常用函数
    linux 下分别使用pip2、pip3
    linux 下切换Python版本(某用户,共存,替换)
  • 原文地址:https://www.cnblogs.com/wt7018/p/11976074.html
Copyright © 2011-2022 走看看