我是pandas
的新手,但是想学习它,但是我必须使用该库为此创建一个函数。我有一个包含伪数据的csv文件source.csv
(链接到文件:pastebin)。其中的关键列为:month, area, name, errors
。对于每月{{1}中的MY WORKS
,下面的area
应该被过滤(?)。对于每项工作,应计算works
列中的问题。如果没有错误,则应考虑0。
errors
字典输出将与import pandas as pd
source_df = pd.read_csv('source.csv') # Sorry guys, don't know how to proceed from here
works = ['WORLD', 'P&G', 'PART D', 'BRIGHTS', 'NOTIFICATION',
'OOP', 'ABCD', 'CHANNEL', 'KENNY DISPLAY', 'Migration']
months = ['January', 'March', 'April', 'May', 'June']
# Expected output:
data = {'WORLD': {'categories': months,
'series': [{
'name': 'Big Issue',
'data': [0, 0, 0, 0, 0] # Number of Big Issues in those months
}, {
'name': 'Small Issue',
'data': [1, 0, 0, 0, 0] # Number of Small Issues in those months
}, {
'name': 'Monitoring',
'data': [0, 2, 0, 0, 0] # Number of Monitorings in those months
}, {
'name': 'Improvement',
'data': [0, 0, 0, 1, 0] # Number of Improvements in those months
}]
},
'P&G': {'categories': months,
'series': [{
'name': 'Big Issue',
'data': [0, 0, 0, 0, 0]
}, {
'name': 'Small Issue',
'data': [0, 0, 0, 1, 0]
}, {
'name': 'Monitoring',
'data': [0, 2, 0, 0, 0]
}, {
'name': 'Improvement',
'data': [0, 0, 0, 1, 0]
}]
}
}
中的其余元素一起完成。上面显示的预期输出仅适用于works
和WORLD
。
答案 0 :(得分:0)
https://gist.github.com/kyogesh/c7c2e3e16e9d9477cad3d6477bfc4bd4
请查看我粘贴在此处的要点。 这将为您提供结果。在这里,您可以根据需要设置数据格式。