Issue : Incorrect pandas indexing with `.ix`
The code uses .ix for indexing in pandas DataFrames, which is deprecated. It should be replaced with .loc or .iloc depending on whether label-based or integer-based indexing is intended. Using .loc is generally preferred when dealing with labels.
Hi! 👋
Just a heads-up: the code is currently using .ix for indexing pandas DataFrames, which has been deprecated since pandas 0.20.0 and removed in later versions.
To ensure compatibility with modern versions of pandas:
- Use
.loc[]for label-based indexing - Use
.iloc[]for integer-based indexing
Old (deprecated)
df.ix[2, 'column_name']
Replace with either:
df.loc[2, 'column_name'] # if 2 is an index label df.iloc[2, df.columns.get_loc('column_name')] # if 2 is a row number
df = pd.DataFrame({"A": [1, 2, 3]}, index=[100, 101, 102]) df.loc[101] # Valid: 101 is a label
df = pd.DataFrame({"A": [1, 2, 3]}, index=["a", "b", "c"]) df.loc[1] # ❌ KeyError, because "1" is not a label
df = pd.DataFrame({"A": [1, 2, 3]}, index=["a", "b", "c"]) df.loc["b"] # Valid