TypeError: barplot() takes from 0 to 1 positional arguments but 2 were given
Question:
Can someone tell me whats wrong here
#stemming all the words to their root word
stemmer = SnowballStemmer(language='english')
stem=[]
for word in lines:
stem.append(stemmer.stem(word))
stem[:20]
#removes stopwords (very common words in a sentence)
stem2 = []
for word in stem:
if word not in nlp.Defaults.stop_words:
stem2.append(word)
#creates a new dataframe for the stem and shows the count of the most used words
df = pd.DataFrame(stem2)
df=df[0].value_counts()
df #shows the new dataframe
I don’t know what’s wrong here, The error I got, when I’m running these code ⬇⬇⬇
#plots the top 20 used words
df = df[:20]
plt.figure(figsize=(10,5))
sns.barplot(df.values, df.index, alpha=0.8)
plt.title('Top Words Overall')
plt.xlabel('Count of words', fontsize=12)
plt.ylabel('Word from Tweet', fontsize=12)
plt.show()
Then got these error
TypeError Traceback (most recent call last)
<ipython-input-20-3371fa9e7860> in <module>
2 df = df[:20]
3 plt.figure(figsize=(10,5))
----> 4 sns.barplot(df.values, df.index, alpha=0.8)
5 plt.title('Top Words Overall')
6 plt.xlabel('Count of words', fontsize=12)
TypeError: barplot() takes from 0 to 1 positional arguments but 2 were given
<Figure size 720x360 with 0 Axes>
Answers:
I’m assuming you’re using seaborn’s barplot function. In the future, it would be helpful to include import statements in your code snippets, so readers know what sns
stands for.
Looking at the seaborn documentation, it looks like barplot
expects x
and y
to be provided as named arguments. In your case, I think you’d want something like this:
sns.barplot(x=df.values, y=df.index, alpha=0.8)
Can someone tell me whats wrong here
#stemming all the words to their root word
stemmer = SnowballStemmer(language='english')
stem=[]
for word in lines:
stem.append(stemmer.stem(word))
stem[:20]
#removes stopwords (very common words in a sentence)
stem2 = []
for word in stem:
if word not in nlp.Defaults.stop_words:
stem2.append(word)
#creates a new dataframe for the stem and shows the count of the most used words
df = pd.DataFrame(stem2)
df=df[0].value_counts()
df #shows the new dataframe
I don’t know what’s wrong here, The error I got, when I’m running these code ⬇⬇⬇
#plots the top 20 used words
df = df[:20]
plt.figure(figsize=(10,5))
sns.barplot(df.values, df.index, alpha=0.8)
plt.title('Top Words Overall')
plt.xlabel('Count of words', fontsize=12)
plt.ylabel('Word from Tweet', fontsize=12)
plt.show()
Then got these error
TypeError Traceback (most recent call last)
<ipython-input-20-3371fa9e7860> in <module>
2 df = df[:20]
3 plt.figure(figsize=(10,5))
----> 4 sns.barplot(df.values, df.index, alpha=0.8)
5 plt.title('Top Words Overall')
6 plt.xlabel('Count of words', fontsize=12)
TypeError: barplot() takes from 0 to 1 positional arguments but 2 were given
<Figure size 720x360 with 0 Axes>
I’m assuming you’re using seaborn’s barplot function. In the future, it would be helpful to include import statements in your code snippets, so readers know what sns
stands for.
Looking at the seaborn documentation, it looks like barplot
expects x
and y
to be provided as named arguments. In your case, I think you’d want something like this:
sns.barplot(x=df.values, y=df.index, alpha=0.8)