ValueError:对象类型< class'pandas.core.series.Series'>没有名为1的轴. [英] ValueError: No axis named 1 for object type <class 'pandas.core.series.Series'>

查看:1854
本文介绍了ValueError:对象类型< class'pandas.core.series.Series'>没有名为1的轴.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编程新手.我正在尝试使用scipy最小化,遇到了几个问题,并解决了大多数问题.

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])

推荐答案

OP没有提供足够的信息,但基本上是在代码中指定的某个位置,以便由数据框列(axis = 1)对对象进行操作熊猫系列.如果代码通常可以正常工作,但偶尔会出现错误,请检查数据帧可能只有1行的退化情况.熊猫习惯于猜测自己想要的内容-可能会决定将1行数据框缩小为一个系列(例如apply()函数;您可以在其中使用reduce=False禁用它).

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).

添加一行代码以检查对象是否为isinstance(df, pd.DataFrame),否则将有问题的熊猫系列转换为数据框,例如s.to_frame().T,以解决我必须处理的问题.

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.

这篇关于ValueError:对象类型< class'pandas.core.series.Series'>没有名为1的轴.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆