title: Coursera Python final project sentiment classifier
body: <p>Finally, copy in your previous functions and write code that opens the file project_twitter_data.csv which has the fake generated twitter data (the text of a tweet, the number of retweets of that tweet, and the number of replies to that tweet). Your task is to build a sentiment classifier, which will detect how positive or negative each tweet is. Copy the code from the code windows above, and put that in the top of this code window. Now, you will write code to create a CSV file called resulting_data.csv, which contains the Number of Retweets, Number of Replies, Positive Score (which is how many happy words are in the tweet), Negative Score (which is how many angry words are in the tweet), and the Net Score (how positive or negative the text is overall) for each tweet. The file should have those headers in that order. Remember that there is another component to this project. You will upload the CSV file to Excel or Google Sheets and produce a graph of the Net Score vs Number of Retweets. Check Coursera for that portion of the assignment, if you’re accessing this textbook from Coursera.</p>
  <p>Need Help with this question. Have been stuck on this one since about 1 week. please help this is the final project.</p>
  <pre><code>punctuation_chars = [&quot;'&quot;, '&quot;', &quot;,&quot;, &quot;.&quot;, &quot;!&quot;, &quot;:&quot;, &quot;;&quot;, '#', '@']
  def strip_punctuation(a):
      for x in punctuation_chars:
          if x in a:
              a = a.replace(x,&quot;&quot;)
      return(a)
  positive_words = []
  with open(&quot;positive_words.txt&quot;) as pos_f:
      for lin in pos_f:
          if lin[0] != ';' and lin[0] != '\n':
              positive_words.append(lin.strip())
  def get_pos(c):
      pos = 0
      b = c.lower()
      b = strip_punctuation(b)
      lst = b.split(&quot; &quot;)
      for i in positive_words:
          for j in lst:
              if i == j:
                  pos+=1
      return pos
  negative_words = []
  with open(&quot;negative_words.txt&quot;) as pos_f:
      for lin in pos_f:
          if lin[0] != ';' and lin[0] != '\n':
              negative_words.append(lin.strip())
  def get_neg(c):
      neg = 0
      b = c.lower()
      b = strip_punctuation(b)
      lst = b.split(&quot; &quot;)
      for i in negative_words:
          for j in lst:
              if i == j:
                  neg+=1
      return neg
  file = open(&quot;project_twitter_data.csv&quot;, &quot;r&quot;)
  e = file.read()
  nega = posi = 0
  for f in e:
      nega += get_neg(f)
      negat = nega*-1
      posi += get_pos(f)
  negat = nega*-1
  ne = str(nega)
  po = str(posi)
  net = posi + negat
  netd = str(net)
  filer = open('resulting_data.csv','w')
  result = filer.write('Number of Retweets, Number of Replies, Positive Score, Negtive Score, Net Score\n')
  result = filer.write('0, 0, ' + ne +', ' + po +&quot;, &quot; + netd + '\n')
  </code></pre>
  <p>This is all I could think off. I cant use import CSV in this. It is not allowing me to.</p>
  <p>some good words -</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>a+
  abound
  abounds
  abundance
  abundant
  accessable
  accessible
  acclaim
  acclaimed
  acclamation</code></pre>
  </div>
  </div>
  
  these words are stored in the file positive_words.txt
  some negative words -</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>2-faced
  2-faces
  abnormal
  abolish
  abominable
  abominably
  abominate
  abomination
  abort</code></pre>
  </div>
  </div>
  </p>
  <p>these words are stored in negative_words.txt
  Twitter data -</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>tweet_text,retweet_count,reply_count
  @twitteruser: On now - @Fusion scores first points #FirstFinals @overwatchleague @umich @umsi Michigan Athletics made out of emojis. #GoBlue,3,0
  BUNCH of things about crisis respons… available July 8th… scholarship focuses on improving me… in North America! A s… and frigid temperatures,1,0
  FREE ice cream with these local area deals: chance to </code></pre>
  </div>
  </div>
  </p>
  <p>Also after this I have to save it in a file that is in CSV format</p>