问题
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