Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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])
like image 430
Eslava Calderón Avatar asked Oct 22 '25 01:10

Eslava Calderón


1 Answers

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.

like image 188
Gary Feng Avatar answered Oct 24 '25 14:10

Gary Feng



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!