Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想制作一个跨越文件夹中多个文件的直方图。例子:
文件 1:
Alpha Beta Ceta Delta
文件 2:
Delta Ceta Alpha
文件 3:
Beta Delta
我知道我可以使用 Numpy 创建直方图: axHistx = plt.axes(range)
axHistx = plt.axes(range)
我如何使用它在多个文件上创建直方图,这给了我字符串出现的绝对数量?
如果您只是想计算所有文件中的实例数,您可以这样做:
counts = {} for f in filenames: for val in [s.strip() for s in open(f).readlines()]: counts[val] = counts.get(val, 0) + 1