df['CVR'].round(2)被报错loop of ufunc does not support argument 0 of type float which has no callable rint method
时间: 2024-03-09 21:48:44 浏览: 37
这个错误是因为你使用了`round()`方法对一个numpy数组进行四舍五入,但是numpy数组的数据类型是float,而float类型没有`rint`方法,导致出错。解决这个问题的方法是使用numpy中的`around()`方法来代替`round()`方法,例如:
```
import numpy as np
df['CVR'] = np.around(df['CVR'], 2)
```
这个代码将`df`中的`CVR`列保留2位小数,并将结果赋值给`CVR`列。使用`around()`方法可以避免出现上述错误,因为该方法可以对numpy数组进行四舍五入。
相关问题
px.funnel(behalf_con,x='指标',y='数值',color='office',text='CVR',option={textStyle:{fontSize: 14}})被返回name 'textStyle' is not defined
当您在函数中使用 `option={textStyle:{fontSize: 14}}` 时,Python 会认为您想要在 `option` 中设置一个键为 `textStyle` 的字典,并将其值设置为 `{fontSize: 14}`。然而,在您的代码中,`textStyle` 并未定义,因此会出现 `name 'textStyle' is not defined` 的错误。
要解决这个问题,您需要在函数中导入 `Option` 对象,然后使用它来设置 `textStyle` 属性。例如:
```python
from pyecharts import options as opts # 导入 Option 对象
def create_funnel_chart(data, x='指标', y='数值', color='office', text='CVR'):
option = opts.InitOpts(
funnel_opts=opts.FunnelOpts(
sort_='ascending',
label_opts=opts.LabelOpts(
position='inside',
formatter='{b} : {c}',
font_size=14 # 设置字体大小为14
)
)
)
c = (
Funnel(init_opts=option)
.add(
"",
[list(z) for z in zip(data[x], data[y])],
sort_="ascending",
label_opts=opts.LabelOpts(position="inside"),
tooltip_opts=opts.TooltipOpts(formatter="{b} : {c}")
)
.set_global_opts(
title_opts=opts.TitleOpts(title=text),
visualmap_opts=opts.VisualMapOpts(is_piecewise=True),
toolbox_opts=opts.ToolboxOpts(),
legend_opts=opts.LegendOpts(is_show=True, pos_top='5%', pos_left='center', orient='horizontal')
)
)
return c
```
在上面的代码中,我们通过导入 `options` 模块并使用 `opts.LabelOpts` 来设置了 `textStyle` 中的 `font_size` 属性为 14。这样可以确保代码正常运行并设置字体大小。
[ccr,cvr,ypredict,ycredict,yc,yp,ys]=pls_da(x1,y1,x2,y2,lv);
这行代码是进行PLS-DA(Projection to Latent Structure Discriminant Analysis)的操作,其中:
x1表示训练数据集的自变量;
y1表示训练数据集的因变量;
x2表示测试数据集的自变量;
y2表示测试数据集的因变量;
lv表示进行PLS-DA的主成分数。
该函数会返回6个结果,分别是:
ccr表示训练集分类准确率;
cvr表示交叉验证的分类准确率;
ypredict表示对测试集进行预测得到的因变量的预测值;
ycredict表示对测试集进行预测得到的因变量的实际值;
yc表示训练集的因变量的预测值;
yp表示训练集的因变量的实际值;
ys表示训练集的残差。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)