【已解决 TypeError: barplot() takes from 0 to 1 positional arguments but 2 were given】

这篇具有很好参考价值的文章主要介绍了【已解决 TypeError: barplot() takes from 0 to 1 positional arguments but 2 were given】。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

已解决 TypeError: barplot() takes from 0 to 1 positional arguments but 2 were given

1.先放代码:

sns.barplot(features_df['特征'][:20],features_df['重要性'][:20]) # 柱形图

报错信息:
【已解决 TypeError: barplot() takes from 0 to 1 positional arguments but 2 were given】,python,pandas
解决方案:代码更改如下

sns.barplot(x=features_df['特征'][:20],y=features_df['重要性'][:20]) # 柱形图

此时不会报错了:
【已解决 TypeError: barplot() takes from 0 to 1 positional arguments but 2 were given】,python,pandas

2.代码更改原理:简要了解一下函数用法

sns.barplot()函数:根据特征重要程度进行排序并输出
先看sns.barplot的官方用法:
【已解决 TypeError: barplot() takes from 0 to 1 positional arguments but 2 were given】,python,pandas

3.函数用法实例

import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
a = pd.DataFrame({"feature": [19, 36, 28, 15, 2, 9, 45, 73, 3, 18, 66, 89]})
b=pd.DataFrame({"importance":[15396,  7812,  4795,  3857,  2966,  1984,  1735,  1266,  1128, 849, 6831, 2637]})
df=pd.concat([a,b],axis=1)
df=df.sort_values(by='importance',ascending=False)
df=df[:10]
print(df)
sns.barplot(x="importance",y="feature",data=df,orient="h",order=df["feature"])

结果:
【已解决 TypeError: barplot() takes from 0 to 1 positional arguments but 2 were given】,python,pandas
总结:不可以对坐标写入的xy省略。横纵坐标轴的写入需要按照官方文档来,不能随意更改和省略。文章来源地址https://www.toymoban.com/news/detail-604557.html

到了这里,关于【已解决 TypeError: barplot() takes from 0 to 1 positional arguments but 2 were given】的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • python执行函数时报错TypeError: create_pointer_down() takes 1 positional argument but 2 were given

     在调用函数时出现了这个报错new_input.create_pointer_down(MouseButton.LEFT) TypeError: create_pointer_down() takes 1 positional argument but 2 were given,意思是说这个函数只接收一个变量,但实际上却给了两个变量,我搜索到说如果这个函数是自己在类里定义的,那么应该在类的函数参数在最前方加

    2023年04月09日
    浏览(30)
  • TypeError: setUpClass() missing 1 required positional argument: ‘cls‘怎么解决?

     解决方法: 分别在  setUpClass(cls)   和   tearDownClass(cls)  前面加  @classmethod

    2024年02月12日
    浏览(25)
  • forward() takes 2 positional arguments but 3 were given

    问题描述: 在forward中明明正确数量的参数,却报错:forward() takes 2 positional arguments but 3 were given; 问题分析: 使用nn.Sequential()定义的网络,只接受单输入 例如: self.backbone=nn.Sequential(nn.lstm(input_size=20, hidden_size=40, num_layers=2),                                     nn.linear(

    2024年02月11日
    浏览(35)
  • 已解决 | python 操作 elasticsearch TypeError: __init__() missing 1 required positional argument: ‘scheme‘

    今天在用 python 跑 elasticsearch 时,代码如下: 此时我本地 es 里是有名为 shopping 的索引的,而且索引中也有些数据,但运行时,报错如下: 这让我有点摸不着头脑,查了网上的 python 操作 es 的入门教程,都没有提到 scheme 这个参数。 最后一想,可能是版本问题,我使用的这个

    2024年02月13日
    浏览(28)
  • 修复 Python 错误TypeError: Missing 1 Required Positional Argument

    类是面向对象编程语言的基本特征之一。 每个对象都属于 Python 中的某个类。 我们可以创建我们的类作为蓝图来创建相同类型的对象。 我们使用 class 在 Python 中定义一个类。 Python 中一个非常重要的特性是在定义类时使用 self 属性。 self 属性表示对象的数据并将参数绑

    2024年02月10日
    浏览(34)
  • Python TypeError: __init__() missing 1 required positional argument 问题

    当我们学完class还未熟练运用,或做题时可能总会遇到这个问题,那我们该怎么解决呢 首先我们先创造一个类,如: 在这里我们建立了两个变量:b2,c1,而当我们传参时,可能是只付了一个变量的值。如: 这样就会产生TypeError: __init__() missing 1 required positional argument 问题。 而

    2024年04月16日
    浏览(31)
  • TypeError: linear(): argument ‘input‘ (position 1) must be Tensor, not numpy.ndarray

    错误:TypeError: linear(): argument ‘input’ (position 1) must be Tensor, not numpy.ndarray 这个错误通常表示您在使用torch.nn.Linear()函数时,将一个numpy数组传递给了该函数,而不是一个Tensor对象。 torch.nn.Linear()函数是用于创建线性层的函数。在PyTorch中,所有的操作都必须使用Tensor对象来完成

    2024年02月15日
    浏览(41)
  • 【学习】python之使用pandas提示TypeError: NDFrame.to_excel() got an unexpected keyword argument ‘encoding‘

    桨桨,终于有东西可以来记录解决的问题点啦~ 背景是在使用pandas一直无法转换成excel,排查了很久,终于在做了一个细微的调整实现成功了。 pandas 是基于NumPy 的一种工具。我的理解:这个包可以实现读取excel,写入excel的功能,分别是readexcel,toexcel。 运行报错提示 Traceback (m

    2024年04月08日
    浏览(79)
  • 已解决TypeError: __init__() got an unexpected keyword argument ‘threshold‘

    已解决(paddleocr模块PPStructure(show_log=True)报错)TypeError: init () got an unexpected keyword argument ‘threshold‘ 粉丝群里面的一个小伙伴想用python cv2模块和paddleocr 模块做图像识别复制别人的代码报错(当时他心里瞬间凉了一大截,跑来找我求助,然后顺利帮助他解决了,顺便记录一下

    2024年02月09日
    浏览(41)
  • Pycharm使用matplotlib报错:TypeError: vars() argument must have __dict__ attribute 解决方法

    源程序: 在 PyCharm(至少在科学项目中)使用交互式控制台运行所有文件,其中使用了后端 module://backend_interagg。 这个后端会导致与您相同的错误。所以。 在你的文件头部添加 mpl.use(‘TkAgg’) ,或者检查你可以使用哪个后端并在此函数中传递这些名称。 在你的文件头部添加

    2024年02月11日
    浏览(25)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包