Link Search Menu Expand Document

Indexing, Selecting

Table of contents

  1. 4 Ways of Indexing and Selecting
  2. MultiIndex and Advanced Indexing
    1. reset_index() Method : 별도 설명

import pandas as pd

4 Ways of Indexing and Selecting

  1. as an attribute
     dataframe.column_name
    
  2. indexing operater []
     dataframe['column_name']                                # -> Series
     dataframe[['column_name_1', 'column_name_2', ...]]      # -> DataFrame
     dataframe['column_name'][5]
    
     dataframe[4:7]
     dataframe['row_index':'row_index']              # slice is only for ROWs
    
  3. iloc attribute : integer
    Allowed inputs are:
    5 (integer),
    [4, 3, 0] (list),
    1:7 (slice),
    dataframe.column_name == 'column_name (condition : boolean array),
    callable function (callable with one argument)

     dataframe.iloc[0]                               # row
     dataframe.iloc[:, 0]                            # row, column
    

    pandas document - pandas.DataFrame.iloc

  4. loc attribute : label
     dataframe.loc['row_label']                      # row
     dataframe.loc['row_label', 'column_name']       # row, column
    

    pandas document - pandas.DataFrame.loc

MultiIndex and Advanced Indexing

reset_index() Method : 별도 설명

In general the multi-index method you will use most often is the one for converting back to a regular index.