我从json文件进行手动计算并导入数据。我想使用python自动执行该过程。我希望根据json文件选择一些值进行计算。下面是示例Json文件,因此,为了计算SayDo公式,我必须根据导演获取总和(已完成的故事点)/总和(已提交的故事点)。在这种情况下,导演是“拉杰什”。你能指出我正确的来源吗?
{"saydo": [{"teamName": "EPAM Backend 1", "sprintName": "MF-S94", "director": "Rajesh", "location": "Ukraine",
"vendors": "EPAM,FTE", "sayDo": 77, "saydoStatusMeassure": "Yellow", "saydoStatusMeassureNumber": 0,
"commitedSayDo": 68, "commitedSaydoStatusMeassure": "Yellow", "commitedSaydoStatusMeassureNumber": 0,
"commitedStories": 17, "completedStories": 16, "completedStoryPoints": 56, "commitedStoryPoints": 73,
"completedSoryPointsWithoutAddedAfterSprintStart": 50, "incompletedStories": 5,
"addedAfterSprintStartStories": 5, "removedStories": 1, "bugsPerDev": 0.75,
"bugsStatusMeassureNumber": 0, "bugsStatusMeassure": "Yellow", "openBeforeSprintEndsBugs": 6,
"membersCount": 12, "completedBugsCount": 9, "p3BugsStatusMeassureNumber": 1,
"p3BugsStatusMeassure": "Green", "p3BugsCount": 1, "addedIssuesAfterSprintCount": 6,
"completedInSprintCount": 9, "techDebtIsuuesCount": 3, "foundAndFixedBugsValue": 100,
"foundAndFixedBugsStatusMeassureNumber": 1, "foundAndFixedBugsStatusMeassure": "Green",
"afterProdStatusMeassureNumber": 1, "afterProdStatusMeassure": "Green", "bugsAfterProdCount": 0}]}
到目前为止,我的代码是
import json
def test3():
with open('C:/Users/erpsaam/Desktop/say-do-statistics-MF-S82-MF-S94-2018-07-09--10-30.json') as f:
d = json.load(f)
print (d['saydo'][1]['director'])
test3()
答案 0 :(得分:0)
您的输入格式很奇怪:我看不出要点 一本字典,其中包含一本字典的清单...
我会做这样的事情:
将熊猫作为pd导入
d = pd.read_json('toto.json')#用您的json文件替换'toto.json'。 df = pd.DataFrame([d ['saydo'] [0]])#将此笨拙的格式转换为常规的熊猫数据框
(df.completedStoryPoints / df.commitedStoryPoints)[df.director =='Rajesh']
不确定要完全理解这个问题:“正确的来源”是什么意思?
答案 1 :(得分:-1)
您可以尝试使用熊猫,请参见read_json。聚合功能很多。