-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread_phoenix_data.py
48 lines (42 loc) · 1.48 KB
/
read_phoenix_data.py
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
# See https://s3.amazonaws.com/oeda/docs/phoenix_codebook.pdf
# for coding descriptions
phoenix_cols = ['event_id',
'date',
'year', 'month', 'day',
'source_actor_full',
'source_actor_entity',
'source_actor_role',
'source_actor_attribute',
'target_actor_full',
'target_actor_entity',
'target_actor_role',
'target_actor_attribute',
'event_code',
'event_root_code',
'penta_class',
'goldstein_score',
'issues',
'lat',
'lon',
'location_name',
'state_name',
'country_code',
'sentence_id',
'urls',
'news_sources']
used_cols = [x for x in phoenix_cols if x not in ['year', 'month', 'day']]
def read_phoenix_data(fnames):
"""
:param str | list[str] fnames: filename or list of filenames to read
"""
import pandas as pd
if isinstance(fnames, str):
fnames = [fnames]
df = pd.concat([pd.read_table(fname,
header=None,
names=phoenix_cols,
usecols=used_cols,
na_values=' ',
parse_dates=['date'])
for fname in fnames])
return df