Python | Pandas DataFrame.ix[ ] (original) (raw)

Last Updated : 26 Jun, 2025

Python's Pandas library is a powerful tool for data analysis, it provides **DataFrame.ix[] method to select a subset of data using both label-based and integer-based indexing.

**Important Note: DataFrame.ix[] method **has been deprecated since Pandas version **0.20.0 and is no longer recommended for use in newer versions. Instead, use **loc[] for **label-based indexing and **iloc[] for integer-based indexing.

Syntax of DataFrame.ix[]

DataFrame.ix[ ]

**Parameters:

**Returns: A DataFrame or Series, depending on the parameters.

**Code #1:

Python3 1== `

importing pandas package

import pandas as geek

making data frame from csv file

data = geek.read_csv("https://media.geeksforgeeks.org/wp-content/uploads/nba.csv")

Integer slicing

print("Slicing only rows(till index 4):") x1 = data.ix[:4, ] print(x1, "\n")

print("Slicing rows and columns(rows=4, col 1-4, excluding 4):") x2 = data.ix[:4, 1:4] print(x2)

`

**Output :

**Code #2:

Python3 1== `

importing pandas package

import pandas as geek

making data frame from csv file

data = geek.read_csv("nba.csv")

Index slicing on Height column

print("After index slicing:") x1 = data.ix[10:20, 'Height'] print(x1, "\n")

Index slicing on Salary column

x2 = data.ix[10:20, 'Salary'] print(x2)

`

**Output:

**Code #3:

Python `

importing pandas and numpy

import pandas as pd import numpy as np

df = pd.DataFrame(np.random.randn(10, 4), columns = ['A', 'B', 'C', 'D'])

print("Original DataFrame: \n" , df)

Integer slicing

print("\n Slicing only rows:") print("--------------------------") x1 = df.ix[:4, ] print(x1)

print("\n Slicing rows and columns:") print("----------------------------") x2 = df.ix[:4, 1:3] print(x2)

`

**Output :

**Code #4:

Python `

importing pandas and numpy

import pandas as pd import numpy as np

df = pd.DataFrame(np.random.randn(10, 4), columns = ['A', 'B', 'C', 'D'])

print("Original DataFrame: \n" , df)

Integer slicing (printing all the rows of column 'A')

print("\n After index slicing (On 'A'):") print("--------------------------") x = df.ix[:, 'A']

print(x)

`

**Output :