add names count, blacken
This commit is contained in:
@@ -6,16 +6,52 @@ import numpy as np
|
||||
from collections import Counter
|
||||
from pprint import pprint
|
||||
|
||||
stop_words = ['of', 'and', 'the', 'we', 'in', 'to', 'what', 'a', 'on', 'an',
|
||||
'do', 'for', 'with', 'is', 'it', 'that', 'this', 'as', 'by',
|
||||
'are', 'using', 'from', 'how', 'has', 'be', 'or', 'can', 'our',
|
||||
'at', 'why', 'when', 'introduction', 'your', 'through']
|
||||
file_path = 'data.csv'
|
||||
stop_words = [
|
||||
"of",
|
||||
"and",
|
||||
"the",
|
||||
"we",
|
||||
"in",
|
||||
"to",
|
||||
"what",
|
||||
"a",
|
||||
"on",
|
||||
"an",
|
||||
"do",
|
||||
"for",
|
||||
"with",
|
||||
"is",
|
||||
"it",
|
||||
"that",
|
||||
"this",
|
||||
"as",
|
||||
"by",
|
||||
"are",
|
||||
"using",
|
||||
"from",
|
||||
"how",
|
||||
"has",
|
||||
"be",
|
||||
"or",
|
||||
"can",
|
||||
"our",
|
||||
"at",
|
||||
"why",
|
||||
"when",
|
||||
"introduction",
|
||||
"your",
|
||||
"through",
|
||||
"et",
|
||||
"al.",
|
||||
"&",
|
||||
"",
|
||||
]
|
||||
file_path = "data.csv"
|
||||
data = []
|
||||
|
||||
|
||||
def parse_csv(file_path):
|
||||
with open(file_path, 'r') as file:
|
||||
with open(file_path, "r") as file:
|
||||
reader = csv.reader(file)
|
||||
for row in reader:
|
||||
data.append(row)
|
||||
@@ -35,10 +71,10 @@ def extract_title_keywords(data):
|
||||
title_keywords = []
|
||||
re_words = []
|
||||
for row in data:
|
||||
raw_words = row[2].split(' ')
|
||||
raw_words = row[2].split(" ")
|
||||
row_words = []
|
||||
for word in raw_words:
|
||||
re_word = re.sub(r'[^a-zA-Z\-]', '', word.lower())
|
||||
re_word = re.sub(r"[^a-zA-Z\-]", "", word.lower())
|
||||
if re_word not in stop_words:
|
||||
re_words.append(re_word)
|
||||
row_words.append(re_word)
|
||||
@@ -50,22 +86,33 @@ def print_title_keywords(data):
|
||||
title_keywords = extract_title_keywords(data)
|
||||
title_keywords = [word[0] for word in title_keywords]
|
||||
count_title_words = Counter(title_keywords).most_common(20)
|
||||
pprint(count_title_words)
|
||||
pprint(count_title_words)
|
||||
|
||||
|
||||
def histogram(data):
|
||||
dates = []
|
||||
dates = []
|
||||
for row in data:
|
||||
dates.append(int(row[4]))
|
||||
years = range(min(dates), max(dates)+2)
|
||||
years = range(min(dates), max(dates) + 2)
|
||||
plt.hist(dates, bins=years)
|
||||
plt.show()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
def names(data):
|
||||
names = []
|
||||
for row in data:
|
||||
name_parts = row[1].split(" ")
|
||||
for name in name_parts:
|
||||
if name not in stop_words:
|
||||
names.append(name)
|
||||
count_names = Counter(names).most_common(20)
|
||||
pprint(count_names)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parse_csv(file_path)
|
||||
data = data[1:]
|
||||
extract_journal_titles(data)
|
||||
print_title_keywords(data)
|
||||
dash_viz(data)
|
||||
names(data)
|
||||
histogram(data)
|
||||
|
||||
Reference in New Issue
Block a user