-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter_process_file.py
More file actions
53 lines (38 loc) · 1.36 KB
/
filter_process_file.py
File metadata and controls
53 lines (38 loc) · 1.36 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
51
####################################
# Author: Emil Polakiewicz
# Date: December 2021
# Purpose: Filter process file to make it smaller
####################################
#####################
# Imports
#####################
import pandas as pd
import os
#####################
# Globals
#####################
BASE_DIR = os.getcwd()
DATA_DIR = os.path.join(BASE_DIR, '../../datasets/kent2016')
chunk_size = 20000000
i = 0
#####################
# Filter Proc File
#####################
# load file into chunks
for proc_chunk in pd.read_csv(os.path.join(DATA_DIR, "proc.txt.gz"), delimiter=",", chunksize=chunk_size,
skiprows=0):
proc_chunk.columns = ['time', 'user', 'comp', 'process', 'start/end']
# Only keep real user account data
proc_chunk = proc_chunk[proc_chunk['user'].str[0] == 'U']
# get rid of process ends
is_proc_start = proc_chunk['start/end'] == 'Start'
proc_chunk = proc_chunk[is_proc_start]
print("Only Process starts Len:" + str(len(proc_chunk)))
# get rid of start/end column, as we only care about processs starts
proc_chunk = proc_chunk.filter(items=['time', 'user', 'comp', 'process'])
# append to file
if i == 0:
proc_chunk.to_csv("filtered_proc.csv", index=False)
else:
proc_chunk.to_csv("filtered_proc.csv", mode='a', header=False, index=False)
i += 1