iloc

     

  • We can slice the rows and columns based on index numbers
  • Index numbers starts from zero
  • It states about index interger location
  • i = index, loc = location
  •  

     

     

    Select first 3 rows by using iloc

     

  • print(df.iloc[1:4])
  •  

     

     

    Print 7 rows from 3rd row(starting from header) of dataframe by using iloc

     

  • df.iloc[1:8]
  • {% for c in range(colscount) %}
    {{headerdata[c]}}
    {% endfor %}
    {% for i in range(rowscount) %}
    {% for c in range(colscount) %}
    {{totalrows[i][c]}}
    {% endfor %}
    {% endfor %}

     

    Print all rows of dataframe by using iloc

     

  • print(df.iloc[:])
  •  

    {% for c in range(colscount) %}
    {{headerdata[c]}}
    {% endfor %}
    {% for i in range(r) %}
    {% for c in range(colscount) %}
    {{rows[i][c]}}
    {% endfor %}
    {% endfor %}

     

    Print 7 rows and 3 columns (from HIGH) of dataframe by using iloc

     

  • print(df.iloc[0:8, 2:5])
  •  

    {% for c in range(col) %}
    {{head[c]}}
    {% endfor %}
    {% for i in range(row) %}
    {% for c in range(col) %}
    {{values[i][c]}}
    {% endfor %}
    {% endfor %}

     

    Print required rows irrespective of Order

     

  • df.iloc[[1,8,4,3,11,2,0]]
  •  

    {% for c in range(colscount) %}
    {{headerdata[c]}}
    {% endfor %}
    {% for i in range(rcount) %}
    {% for c in range(colscount) %}
    {{v[i][c]}}
    {% endfor %}
    {% endfor %}