Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Python
  3. Question
Python

Building multi-regression model throws an error: `Pandas data cast to numpy dtype of object. Check input data with np.asarray(data).`

Asked by Carol Bower Jun 16, 2021 3.6K views 1 answer
Share

About this question

I have pandas data frame with some categorical predictors (i.e. variables) as 0 & 1 and some numeric variables. When I fit that to a stasmodel like:

est = sm.OLS(y, X).fit()

It throws:

Pandas datacast to numpy dtype of object. Check input data with np.asarray(data). 

I converted all the dtypes of the DataFrame using 

df.convert_objects(convert_numeric=True)

After this, all dtypes of data frame variables appear as int32 or int64. But in the end it still shows dtype: object, like this:

4516        int32
4523        int32
4525        int32
4531        int32
4533        int32
4542        int32
4562        int32
sex         int64
race        int64
dispstd     int64
age_days    int64
dtype: object

Here 4516, 4523 are variable labels.


Any idea? I need to build a multi-regression model on more than hundreds of variables. For that, I have concatenated 3 pandas DataFrames to come up with final DataFrame to be used in model building.

Your answer

1 Answer

More Python discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Python Blogs

Guides, tips and career advice on Python from JanBask experts.