Indexing, Selecting
Table of contents
import pandas as pd
4 Ways of Indexing and Selecting
- as an attribute
dataframe.column_name
- 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
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
- loc attribute : label
dataframe.loc['row_label'] # row dataframe.loc['row_label', 'column_name'] # row, column
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.