-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathannualizer.py
More file actions
40 lines (35 loc) · 1.45 KB
/
Copy pathannualizer.py
File metadata and controls
40 lines (35 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import pandas as pd
def annualizer(data,datapool,sentiment=0,ybase=1986,ymax=2017,margin=0.1):
"""
Args:
data (pd): a panda containing a subset of data with a scores and a year atribute
datapool(pd): a superset of data to which you want to relativize data
sentiment(int): 0 means you want to count all, >0 means to only count positive,
<0 means to only count negative
ybase: start point in year attribute
ymax: end point in year attribute
margin: a value between 1 and 0 to set how agressiveley the programm assigns neutal values"""
#ybase = 1986
year = 0
yeararray = []
if sentiment > 0:
data = data.drop(data[data.scores < margin].index)
if sentiment < 0:
data = data.drop(data[data.scores >= -margin].index)
while year + ybase < ymax:
ycurrent = ybase + year
if ((data[data['year']== ycurrent].shape[0]) != 0):
size = (data[data['year']== ycurrent].shape[0])/(datapool[datapool['year']== ycurrent].shape[0])
else:
size = 0
yeararray.append(size)
year =year+1
return(yeararray)
def keywordsearch(df,keys):
"""
Args:
data (pd): a panda containing a subset of data with a title and a year atribute
keys: the strings you are searching for, sensitive to spaces and capitalization given in this form " Lorem | Ipsum | etc "
"""
dfr = df[df['title'].str.contains(keys,na=False)]
return(dfr)