Created
December 25, 2015 18:08
-
-
Save tmiz/b55d7c367830ef46d309 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import numpy as np | |
from sets import Set | |
with open("BusinessSpending.json") as f: | |
data = json.load(f, 'latin-1') | |
entries = data["raw_data"] | |
keys = [] | |
for entry in entries: | |
keys = entry.keys() | |
countOfArbitaryOrders = 0 | |
expenditureOfAllOrders = [] | |
expenditureOfArbitaryOrders = [] | |
vendors = Set([]) | |
cost_and_venders = [] | |
for entry in entries: | |
expenditureOfAllOrders.append(int(entry["expenditure"])) | |
if entry["number_of_bidders"] == u"随意契約": | |
countArbitaryOrders+=1 | |
expenditureOfArbitaryOrders.append(int(entry["expenditure"])) | |
vendors.add(entry["spending_destination"]) | |
cost_and_venders.append((entry["spending_destination"], | |
int(entry["expenditure"]))) | |
npa_expenditures = np.array(expenditureOfArbitaryOrders) | |
npa_expendituresAll = np.array(expenditureOfOrders) | |
print u"%d件/全体%d件(%2.1f%)" % (len(npa_expenditures), | |
len(npa_expendituresAll), | |
len(npa_expenditures)*100.0/len(npa_expendituresAll)) | |
print u"%d億円/全体%d億円(%2.1f%)" % (npa_expenditures.sum()/100000000, | |
npa_expendituresAll.sum()/100000000, | |
npa_expenditures.sum()*100.0/expendituresAll.sum()) | |
print u"全部で%dベンダー" % len(vendors) | |
dic = {} | |
for vendor in vendors: | |
for cost_and_vender in cost_and_venders: | |
if cost_and_vender[0] == vendor: | |
if not dic.has_key(vendor): | |
dic[vendor] = cost_and_vender[1] | |
else: | |
dic[vendor] += cost_and_vender[1] | |
for k, v in sorted(dic.items(), key=lambda x:-x[1]): | |
print u"%s %d億円 %2.1f%" % (k, v/100000000, v*100.0/expenditures.sum()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment