Parsing A Tweet Inside A Csv Column In Python
I am trying to extract the hashtags in a tweet. All of the tweets are in one column in a csv file. Although, there are resources on parsing strings and putting the extracted hashta
Solution 1:
Actually, your problem is probably just a syntax problem. You are calling tweet = line[1:2]
. In python, this says 'take a slice from 1 - 2', which is logically what you want. Unfortunately, it returns the answer as a list -- so you end up with [tweet] instead of tweet!
Try changing that line to tweet = line[1]
and see if that fixes your problem.
On a separate note, this is probably just a typo on your part, but I think you might want to check your indentation -- I think it should look like
for line in reader:
tweet = line[1:2] #This is the column that contains the tweetsfor x in tweet:
match = re.findall(r"#(\w+)", x)
if match: print x
unless I'm misunderstanding your logic.
Post a Comment for "Parsing A Tweet Inside A Csv Column In Python"