【发布时间】:2018-04-27 16:23:25
【问题描述】:
我正在编写一些 python 代码来进行一些计算并将结果写入文件。这是我当前的代码:
for name, group in data.groupby('Date'):
df = lot_of_numpy_calculations(group)
with open('result.csv', 'a') as f:
df.to_csv(f, header=False, index=False)
计算和写入有时都需要。我读了一些关于 python 中的异步的文章,但我不知道如何实现它。有没有一种简单的方法来优化这个循环,使它不会等到写入完成并开始下一次迭代?
【问题讨论】:
标签: python python-multithreading python-asyncio