파이썬(Python)/Pandas

pandas.DataFrame.iloc

leebaro 2017. 8. 22.
728x90

DataFrame.iloc


정의

 - 정수 값을 이용해 데이터프레임의 특정 위치를 인덱스 기반으로 선택한다.


.iloc[]는 주로 0부터 축의 길이 -1 사이의 정수값으로 사용 가능 가능하지만, boolean array를 사용할 수도 있다.


아래와 같이 이용 가능하다


  • An integer, e.g. 5.
  • A list or array of integers, e.g. [4, 3, 0].
  • A slice object with ints, e.g. 1:7.
  • A boolean array.
  • callable function with one argument (the calling Series, DataFrame or Panel) and that returns valid output for indexing (one of the above)


예제 코드

In [56]: s1 = pd.Series(np.random.randn(5), index=list(range(0,10,2))) In [57]: s1 Out[57]: 0 0.695775 2 0.341734 4 0.959726 6 -1.110336 8 -0.619976 dtype: float64 In [58]: s1.iloc[:3] Out[58]: 0 0.695775 2 0.341734 4 0.959726 dtype: float64 In [59]: s1.iloc[3] Out[59]: -1.1103361028911669



Reference

https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.iloc.html


728x90