0
$\begingroup$

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

$\endgroup$
  • 1
    $\begingroup$ How do you define 'bad' and 'good'? Got a dataset of examples of those? Please expand your question. $\endgroup$ – Jurgy Nov 30 '17 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$ – Dhanshree Bagal Nov 30 '17 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 '17 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$ – Dhanshree Bagal Nov 30 '17 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 '17 at 16:42
1
$\begingroup$

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

df['yourcolumn_name_good_bad'].value_counts().plot(kind='bar')

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

$\endgroup$
0
$\begingroup$

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?
    pass


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

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'])
    plt.show()

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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