Skip to content
Advertisement

scikit-learn LinearRegression IndexError

I am working on a LinearRegression model to fill the null values for the feature Rupeepersqft. When I run the code, I am receiving this error:

JavaScript

This is the code which gives me the error:

JavaScript

This is how the data looks like:

Data2

Can anyone help me out with this?

Advertisement

Answer

To assign values to a column in Pandas.DataFrame you should use the locators, i.e., loc and iloc (for array-like manipulations), so to fix your issue try changing the

JavaScript

to:

JavaScript

which will chose all the rows (the :), and the column Rupeepersqft, and assign whatever values you have on the right.

or by using the iloc:

JavaScript

to assign it to the all rows (again by : operator) of the 1st column of the DataFrame.

Just make sure the values on the right are of the same length as the column you try to assign it to.

More on Pandas you can find in this book.

Cheers

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement