✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

Principal Component Analysis in Python

On the Principal Component Analysis in Python page, the example using the Iris Dataset had code using .ix , which is deprecated.

split data table into data X and class labels y

X = df.ix[:,0:4].values
y = df.ix[:,4].values

How would you rewrite that code using .loc or .iloc?

Do you mean this:

x = df.iloc[:,0:3].values
x = df.loc[:,['ColA','ColB','ColC']].values

y = df.iloc[:,3].values
y = df.loc[:,'ColD'].values
1 Like