0
{
id: "1698627066",
screen_name: "RomanceInfinity",
text: [
"Going NYP to have lunch with bro because I got too much time in between!!!",
"nyp"
],
stance: "",
source: "<a href="http://twitter.com/download/iphone" rel="nofollow">Twitter for iPhone</a>",
fromid: "411377814521147392",
favourite: "false",
date: "2013-12-13 14:11:28",
replyto: "",
replytoid: "",
retweetfrom: "",
domaintype: "",
keywords: [
"nyp"
],
ratio: "",
latitude: 1000,
longitude: 1000,
retweet: 0,
mood_joy: "0.0",
mood_sadness: "0.0",
mood_surprised: "0.0",
mood_disgusted: "0.0",
mood_anger: "1.0",
_version_: 1454285708574326800
},
{

Is there a way that I count each word in the sentence using facet " Going NYP to have lunch with bro because I got too much time in between!!"?
For example having a results of Going =1 Nyp =1 lunch =1 and also not counting the punctuation?

Nalaka526
  • 11,278
  • 21
  • 82
  • 116

1 Answers1

0

Extract the text from the dict using:

name_of_dict['text'][0]

This will extract the sentence:

Going NYP to have lunch with bro because I got too much time in between!!!

To ignore any punctuation you can use a function such as .replace() via:

str = "Going NYP to have lunch with bro because I got too much time in between!!!";
print str.replace("!", "");
>>> Going NYP to have lunch with bro because I got too much time in between

Last, I refer you to this post for counting occurance in a string:

Efficiently calculate word frequency in a string

To which a viable solution is:

from collections import Counter

test = 'abc def abc def zzz zzz'
Counter(test.split()).most_common()
[('abc', 2), ('zzz', 2), ('def', 2)]
Community
  • 1
  • 1
Matt Stokes
  • 4,618
  • 9
  • 33
  • 56