Skip to content
Advertisement

How do I load a dataframe in Python sklearn?

I did some computations in an IPython Notebook and ended up with a dataframe df which isn’t saved anywhere yet. In the same IPython Notebook, I want to work with this dataframe using sklearn.

df is a dataframe with 4 columns: id (string), value(int), rated(bool), score(float). I am trying to determine what influences the score the most just like in this example. There they load a standard dataset, but instead I want to use my own dataframe in the notebook.

JavaScript

But I get the AttributeError that the 'DataFrame' object has no attribute 'data'

Advertisement

Answer

Ok, so some clarifications first: in your example, it is unclear what the load_boston() function does. they just import it. whatever that function returns has an attribute called “data”.

They use this line:

JavaScript

to create a dataframe. Your situation is different because you have a dataframe already and dataframes don’t have an attribute “.data”. Hence, the error you’re getting: “DataFrame’ object has no attribute ‘data’.

What you need is simply

JavaScript

or if you need only some of the columns from you dataframe:

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