Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
binary-classification-of-tweets-about-protest/statanalysis.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
42 lines (35 sloc)
991 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import pandas as pd | |
def special_count(string): | |
count = 0 | |
for char in string: | |
if char.isalpha(): | |
continue | |
elif char.isdigit(): | |
continue | |
elif char.isspace(): | |
continue | |
else: | |
count += 1 | |
return count | |
def quote_count(string): | |
count = 0 | |
for char in string: | |
if char == '"': | |
count += 1 | |
return count | |
def markup_count(string): | |
count = len(re.findall('[<U+]......[>]',string)) | |
return count | |
def punct_count(string): | |
count = 0 | |
for char in string: | |
if char in ('!', "," ,"\'" ,";" ,"\"", ".", "-" ,"?"): | |
count += 1 | |
return count | |
df = pd.read_csv('latest.csv',encoding='ISO-8859-1',usecols=['text']) | |
values = df.values | |
df["special_char_count"] = df["text"].apply(special_count) | |
df["quote_count"] = df["text"].apply(quote_count) | |
df["markup_count"] = df["text"].apply(markup_count) | |
df["punct_count"] = df["text"].apply(punct_count) |