Created
June 15, 2018 02:30
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
In [18]: data = """ | |
...: a, 1.324171 | |
...: b, 0.000126 | |
...: c, 1.970941 | |
...: a, 1.469649 | |
...: b, 0.000124 | |
...: c, 0.512929 | |
...: a, 1.290920 | |
...: b, 0.000118 | |
...: c, 0.259524 | |
...: a, 0.495958 | |
...: b, 0.000123 | |
...: c, 0.910949 | |
...: a, 1.268038 | |
...: b, 0.000118 | |
...: c, 1.016419 | |
...: a, 1.856081 | |
...: b, 0.000120 | |
...: c, 1.400075 | |
...: a, 1.314131 | |
...: b, 0.000140 | |
...: """ | |
In [19]: result = {} | |
...: for line in data.splitlines(): | |
...: if not line: continue | |
...: key, value = line.split(",") | |
...: result.setdefault(key, []).append(float(value)) | |
...: | |
In [20]: for key, values in result.items(): | |
...: print(f"{key}: avg: {sum(values) / len(values)}, sum: {sum(values)}") | |
...: | |
a: avg: 1.2884211428571428, sum: 9.018948 | |
b: avg: 0.00012414285714285714, sum: 0.000869 | |
c: avg: 1.0118061666666667, sum: 6.070837 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment