2016-09-14 58 views
-2

我有形式的数据:验证python脚本的

submission #,scores 
882,"Overall evaluation: 1 
Invite to interview: 1 
Strength or novelty of the idea (1): 4 
Strength or novelty of the idea (2): 4 
Strength or novelty of the idea (3): 3 
Use or provision of open data (1): 3 
Use or provision of open data (2): 3 
""Open by default"" (1): 4 
""Open by default"" (2): 4 
Value proposition and potential scale (1): 2 
Value proposition and potential scale (2): 1 
Market opportunity and timing (1): 3 
Market opportunity and timing (2): 1 
Triple bottom line impact (1): 2 
Triple bottom line impact (2): 2 
Triple bottom line impact (3): 4 
Knowledge and skills of the team (1): 1 
Knowledge and skills of the team (2): 2 
Capacity to realise the idea (1): 1 
Capacity to realise the idea (2): 3 
Capacity to realise the idea (3): 1 
Appropriateness of the budget to realise the idea: 3" 
882,"Overall evaluation: 2 
Invite to interview: 3 
Strength or novelty of the idea (1): 4 
Strength or novelty of the idea (2): 1 
Strength or novelty of the idea (3): 4 
Use or provision of open data (1): 4 
Use or provision of open data (2): 3 
""Open by default"" (1): 3 
""Open by default"" (2): 4 
Value proposition and potential scale (1): 4 
Value proposition and potential scale (2): 4 
Market opportunity and timing (1): 4 
Market opportunity and timing (2): 4 
Triple bottom line impact (1): 4 
Triple bottom line impact (2): 1 
Triple bottom line impact (3): 3 
Knowledge and skills of the team (1): 3 
Knowledge and skills of the team (2): 2 
Capacity to realise the idea (1): 2 
Capacity to realise the idea (2): 3 
Capacity to realise the idea (3): 3 
Appropriateness of the budget to realise the idea: 3" 
883,"Overall evaluation: 1 
Invite to interview: 1 
Strength or novelty of the idea (1): 4 
Strength or novelty of the idea (2): 3 
Strength or novelty of the idea (3): 4 
Use or provision of open data (1): 2 
Use or provision of open data (2): 3 
""Open by default"" (1): 3 
""Open by default"" (2): 3 
Value proposition and potential scale (1): 2 
Value proposition and potential scale (2): 1 
Market opportunity and timing (1): 3 
Market opportunity and timing (2): 1 
Triple bottom line impact (1): 1 
Triple bottom line impact (2): 4 
Triple bottom line impact (3): 2 
Knowledge and skills of the team (1): 3 
Knowledge and skills of the team (2): 3 
Capacity to realise the idea (1): 1 
Capacity to realise the idea (2): 3 
Capacity to realise the idea (3): 4 
Appropriateness of the budget to realise the idea: 3" 
883,"Overall evaluation: 1 
Invite to interview: 1 
Strength or novelty of the idea (1): 2 
Strength or novelty of the idea (2): 2 
Strength or novelty of the idea (3): 1 
Use or provision of open data (1): 2 
Use or provision of open data (2): 1 
""Open by default"" (1): 3 
""Open by default"" (2): 2 
Value proposition and potential scale (1): 2 
Value proposition and potential scale (2): 2 
Market opportunity and timing (1): 2 
Market opportunity and timing (2): 2 
Triple bottom line impact (1): 1 
Triple bottom line impact (2): 2 
Triple bottom line impact (3): 2 
Knowledge and skills of the team (1): 4 
Knowledge and skills of the team (2): 2 
Capacity to realise the idea (1): 2 
Capacity to realise the idea (2): 2 
Capacity to realise the idea (3): 3 
Appropriateness of the budget to realise the idea: 3" 
885,"Overall evaluation: 2 
Invite to interview: 1 
Strength or novelty of the idea (1): 2 
Strength or novelty of the idea (2): 2 
Strength or novelty of the idea (3): 2 
Use or provision of open data (1): 2 
Use or provision of open data (2): 2 
""Open by default"" (1): 2 
""Open by default"" (2): 2 
Value proposition and potential scale (1): 1 
Value proposition and potential scale (2): 2 
Market opportunity and timing (1): 2 
Market opportunity and timing (2): 1 
Triple bottom line impact (1): 2 
Triple bottom line impact (2): 1 
Triple bottom line impact (3): 1 
Knowledge and skills of the team (1): 4 
Knowledge and skills of the team (2): 2 
Capacity to realise the idea (1): 1 
Capacity to realise the idea (2): 3 
Capacity to realise the idea (3): 2 
Appropriateness of the budget to realise the idea: 3" 

和下面的python脚本:

map = {} 
lines=open("new_data.csv",'r').read().splitlines() 
for l in lines: 
    data = l.split('"Overall evaluation:') 
    if len(data) == 2: 
     if data[0] not in map.keys(): 
      map[data[0]] = (0,0) 
     map[data[0]] = (map[data[0]][0]+int(data[1]) , map[data[0]][1]+1) 
for x, y in map.items(): 
    print(str(x) + ", " + str(y[0]/y[1])) 

什么,我认为正在发生的事情是,它需要的两个Overall evaluation:数字的平均值并将其输出到提交号码旁边,是否正确?

+0

顺便说一句,如果你的'map'是一个'collections.defaultdict(lambda:(0,0))',那么读起来会更容易一些 - 这样你就可以用条件逻辑来处理未跟踪的情况你的循环。 –

+0

@CharlesDuffy CR想要代码OP写入,而不是代码他们想要解释给他们 – jonrsharpe

+0

(使用变量名'map'也是不幸的,因为它与内置函数冲突)。 –

回答

1

您的map值是每个元组对应于所看到的项目数和相同项目看到的所有值的总和。

划分两个确实会返回平均值(尽管因为它们是整数,所以结果是四舍五入的 - 如果想要浮点结果而不是整数结果,可以考虑将一个或两个都转换为浮点)。

+0

因此它会输出从两位评论者那里收到的所有分数的平均值?我应该把帖子转到CR吗? :/ –

+0

不,不要将它移动到CR - @jonrsharpe是正确的,你没有写自己的代码不受欢迎。除非使用Python 3,否则它是平均值*,但是四舍五入为浮点值* –

+0

err,除非使用Python 3,否则“舍入为整数值”。 –