-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathposts.py
More file actions
50 lines (42 loc) · 1.69 KB
/
posts.py
File metadata and controls
50 lines (42 loc) · 1.69 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
41
42
43
44
45
46
47
48
49
50
import pandas as pd
eventsDictionary = {
"link": 1,
"photo": 2,
"status": 3,
"video": 4
}
eventsCodesDictionary = {
1: "link",
2: "photo",
3: "status",
4: "video"
}
def prepareDataPosts():
posts = readData()
events, states = splitEventsStatesPosts(posts)
return events, states
def readData():
return pd.DataFrame(readCSV())
def readCSV():
posts = pd.read_csv("./data/posts.csv", sep=",", parse_dates=["status_published"], dayfirst=False)
posts = posts.sort_values(by = ["status_published"], ascending = True)
posts.reset_index(drop=True, inplace=True)
reaction = [sum(entry[5:9]) - sum(entry[10:12]) for _, entry in posts.iterrows()]
mapping = [eventsDictionary.get(entry.loc["status_type"]) for _, entry in posts.iterrows()]
posts.insert(3, "reaction", reaction)
posts.insert(3, "event_mapping", mapping)
posts = posts.drop(columns = ["status_id","status_type","num_reactions","num_comments","num_shares","num_likes","num_loves","num_wows","num_hahas","num_sads","num_angrys","Column1","Column2","Column3","Column4"])
posts = posts.rename(columns={"status_published": "date_time", "event_mapping": "code", "reaction": "value"})
return posts
def splitEventsStatesPosts(dataframe):
events = dataframe.loc[:,["date_time", "code"]]
states = dataframe.loc[:,["date_time", "value"]]
return events, states
def describePatternsPosts(patterns):
describedPatterns = []
for pattern in patterns:
describedPattern = []
for elem in pattern:
describedPattern.append(eventsCodesDictionary[elem])
describedPatterns.append(describedPattern)
return describedPatterns