ValueError: No axis named 1 for object type <class 'pandas.core.series.Series'>

二次信任 提交于 2019-12-24 10:01:11

问题


I´m new to programming. I´m trying to use scipy minimize, had several issues and gotten through most of them.

Right now this is the code, but I'm not understanding why I´m getting this error.

par_opt = so.minimize(fun=fun_obj, x0=par_ini, method='Nelder-Mead', args=[series_pt_cal, dt, series_caudal_cal])

回答1:


Not enough info is given by the OP, but basically somewhere in the code it's specified to operate by data frame column (axis=1) on an object that is a Pandas Series. If the code typically works but occasional gives errors, check for degenerative cases where a data frame may have only 1 row. Pandas has a nasty habit of guessing what you want -- it may decide to reduce a 1-row data frame to a Series (e.g., the apply() function; you can disable that by using reduce=False in there).

Add a line of code to check the object is isinstance(df, pd.DataFrame) or else convert the offending pandas Series to a data frame, something like s.to_frame().T for the problems I had to deal with.



来源:https://stackoverflow.com/questions/43269973/valueerror-no-axis-named-1-for-object-type-class-pandas-core-series-series

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!