熊猫DataReader不适用于多处理

时间:2019-04-27 15:44:50

标签: python-multiprocessing

Pandas数据读取器不适用于多处理/多线程。

我试图将数据读取器与多处理一起使用以加快代码的速度,但是该功能在web.DataReader命令处崩溃。

非常感谢您的帮助!

import pandas_datareader.data as web
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import datetime as dt
import os
import time
from multiprocessing import Process

tickerlist = [['AAPL', 'GOOGL', 'NFLX'], ['AMZN', 'AMD', 'MSFT'], ['TSLA', 'SNAP', 'JPM'], ['GS', 'BA', 'TWTR']]
def test_function(tickerlist, start, end, number):

    for ticker in tickerlist:
        try:
            df = web.DataReader(ticker, 'yahoo', start, end)
            print("datareader works")
        except:
            print("Could not import")

prc = []
for k in range(0, 4):
    prcss = Process(target=test_function, args=(tickerlist[k], dt.datetime(2019,1,2), dt.datetime(2019,4,26), k))
    prcss.start()
    print(prcss)
    prc.append(prcss)

for prcs in prc:
    prcs.join()

print("Code finished")

输出:

<Process(Process-1, started)>
<Process(Process-2, started)>
<Process(Process-3, started)>
<Process(Process-4, started)>
Code finished

0 个答案:

没有答案