-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathanalyze.py
More file actions
78 lines (74 loc) · 2.44 KB
/
analyze.py
File metadata and controls
78 lines (74 loc) · 2.44 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import csv
import locale
import numpy as np
locale.setlocale( locale.LC_ALL, '' ) # Set currency format for USD
def clean(comp):
if comp[0] == ' ':
comp = comp[1:]
if comp[0] == ' ':
comp = comp[1:]
comp = filter(lambda x: x.isalpha() or x.isspace(), comp)
if comp[-1] == " ":
return comp[0:-1]
return comp
def pretty(fund):
return locale.currency(fund, grouping=True)
with open('data.csv', 'rb') as csvfile:
reader = csv.reader(csvfile, delimiter=',')
first = True
data = {} # Competition : [Funds]
alive = {} # Competition : [Funds]
dead = {} # Competition : [Funds]
datas = 0
alives = 0
deads = 0
for row in reader:
# row: [competition, year, startup, fund, source of fund, URL, ...]
if first:
first = False
else:
if row[2][0] == '$':
fund = int(row[2][1:-3].replace(",", ""))
for comp in row[9].replace("\n", "").split(","):
comp = clean(comp)
if fund != 0:
datas += 1
if comp in data:
data[comp].append(fund)
else:
data[comp] = [fund]
if row[3] == "Yes":
alives += 1
if comp in alive:
alive[comp].append(fund)
else:
alive[comp] = [fund]
else:
deads += 1
if comp in dead:
dead[comp].append(fund)
else:
dead[comp] = [fund]
print "For all companies, with", datas, "number of data:"
for comp in data:
print " For competition,", comp, "with", len(data[comp]), "number of data:"
print " average fund is", pretty(np.mean(data[comp]))
print " min fund is", pretty(min(data[comp]))
print " max fund is", pretty(max(data[comp]))
print " median fund is", pretty(np.median(data[comp]))
print ""
print "For alive companies, with", alives, "number of data:"
for comp in alive:
print " For competition,", comp, "with", len(alive[comp]), "number of data:"
print " average fund is", pretty(np.mean(alive[comp]))
print " min fund is", pretty(min(alive[comp]))
print " max fund is", pretty(max(alive[comp]))
print " median fund is", pretty(np.median(alive[comp]))
print ""
print "For dead or unkown companies, with", deads, "number of data:"
for comp in dead:
print " For competition,", comp, "with", len(dead[comp]), "number of data:"
print " average fund is", pretty(np.mean(dead[comp]))
print " min fund is", pretty(min(dead[comp]))
print " max fund is", pretty(max(dead[comp]))
print " median fund is", pretty(np.median(dead[comp]))