pandas
  1. pandas-dataframeiloc

DataFrame.iloc[] - ( Pandas Data Operations and Processing )

Heading h2

Syntax

DataFrame.iloc[row_index,column_index]

Example

import pandas as pd

df = pd.DataFrame({'Name':['John', 'Sally', 'Mike'], 'Age':[25, 30, 35], 'Salary':[50000, 70000, 60000]})

# Selecting the first row and second column (index starts from 0)
value = df.iloc[0,1]

print(value)

Output

25

Explanation

DataFrame.iloc[] is a function in the Pandas library that selects data from a DataFrame based on the integer position of rows and columns. It is similar to the DataFrame.loc[] function, but instead of using labels, it uses integer positions to select the data.

In the above example, we create a DataFrame object with three columns and three rows. We then select the first row and second column using the iloc[] function and store it in the variable value. The iloc[] function uses the integer positions to select the data, with the first index representing the row and the second index representing the column.

Use

DataFrame.iloc[] function is useful in selecting or manipulating data in a Pandas DataFrame based on integer positions of rows and columns. It is a powerful tool that enables the user to perform various operations on the DataFrame.

Important Points

  • DataFrame.iloc[] function is used to select or manipulate data in a Pandas DataFrame based on integer positions of rows and columns.
  • It is similar to the DataFrame.loc[] function, but uses integer positions instead of labels to select the data.
  • The function takes in parameters that represent the integer positions of rows and columns.
  • The function returns the selected data or performs the underlying operation on the selected data.

Summary

In conclusion, DataFrame.iloc[] is a powerful function in the Pandas library that enables the user to select or manipulate data in a DataFrame based on integer positions of rows and columns. It is useful in performing various operations on the DataFrame, such as selecting rows and columns, updating values, and applying functions to the data.

Published on: