I wanna Search how many times "bad" and "good" words are repeated in the data frame and visualize this with histogram.

  • 1
    $\begingroup$ How do you define 'bad' and 'good'? Got a dataset of examples of those? Please expand your question. $\endgroup$
    – Jurgy
    Nov 30, 2017 at 13:48
  • $\begingroup$ I just want to visualize how many times 'bad' word and 'good' word has repeated in particular column of data frame. $\endgroup$ Nov 30, 2017 at 14:05
  • $\begingroup$ If you want to specifically use nltk (since you have tagged nltk) there are many way to do this. For example tokenizing and getting word frequency. Give us a nice workable example, we can help you. $\endgroup$
    – i.n.n.m
    Nov 30, 2017 at 15:35
  • $\begingroup$ Visualise the positive and negative words distribution (Hint: Histogram) This is actual question for which i am searching the answer. I have the list of positive and negative words @i.n.n.m $\endgroup$ Nov 30, 2017 at 16:38
  • $\begingroup$ @DhanshreeBagal So, you just need a histogram for your list? if so, just use value_counts. $\endgroup$
    – i.n.n.m
    Nov 30, 2017 at 16:42

2 Answers 2


Jurgy's answer should work. However, based on comments above, you can simply do like this,


Otherwise, if you want to use seaborn library and create a plot follow this.


Without any knowledge how you would define 'good' or 'bad' this would be the general approach:

def count_good(text):
    # TODO: how do you define good?

def count_bad(text):
    # TODO: how do you define bad?

def analyze(df)
    good_count = df.words.apply(count_good).sum()
    bad_count = df.words.apply(count_bad).sum()

    plt.bar([0, 1], [good_count, bad_count])
    plt.xticks([0, 1], ['Good', 'Bad'])

But you really need to improve your question if you want a serious answer.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.