TypeError: barplot() 采用 0 到 1 个位置参数,但给出了 2 个

-1 python bar-chart seaborn

有人可以告诉我这里出了什么问题吗

\n
#stemming all the words to their root word\nstemmer = SnowballStemmer(language='english')\nstem=[]\nfor word in lines:\n    stem.append(stemmer.stem(word))\nstem[:20]\n#removes stopwords (very common words in a sentence)\nstem2 = []\nfor word in stem:\n    if word not in nlp.Defaults.stop_words:\n        stem2.append(word)\n#creates a new dataframe for the stem and shows the count of the most used words\ndf = pd.DataFrame(stem2)\ndf=df[0].value_counts()\ndf #shows the new dataframe\n
Run Code Online (Sandbox Code Playgroud)\n

我不知道这里出了什么问题,当我运行这些代码时遇到的错误 \xe2\xac\x87\xe2\xac\x87\xe2\xac\x87

\n
#plots the top 20 used words\ndf = df[:20]\nplt.figure(figsize=(10,5))\nsns.barplot(df.values, df.index, alpha=0.8)\nplt.title('Top Words Overall')\nplt.xlabel('Count of words', fontsize=12)\nplt.ylabel('Word from Tweet', fontsize=12)\nplt.show()\n
Run Code Online (Sandbox Code Playgroud)\n

然后得到这些错误

\n
    TypeError                                 Traceback (most recent call last)\n<ipython-input-20-3371fa9e7860> in <module>\n      2 df = df[:20]\n      3 plt.figure(figsize=(10,5))\n----> 4 sns.barplot(df.values, df.index, alpha=0.8)\n      5 plt.title('Top Words Overall')\n      6 plt.xlabel('Count of words', fontsize=12)\n\nTypeError: barplot() takes from 0 to 1 positional arguments but 2 were given\n<Figure size 720x360 with 0 Axes>\n
Run Code Online (Sandbox Code Playgroud)\n

rpm*_*rpm 8

我假设您正在使用 seaborn 的 barplot 函数。将来,在代码片段中包含 import 语句会很有帮助,这样读者就知道sns代表什么。

查看seaborn文档,它看起来像barplot期望xy作为命名参数提供。就你而言,我想你会想要这样的东西:

sns.barplot(x=df.values, y=df.index, alpha=0.8)
Run Code Online (Sandbox Code Playgroud)