2017-07-17 10 views
0

タイトルによると、特定の列のDataFrameを一意の値でスライスしてドライブに保存するasyncioイベントループを記述できますか?そしておそらくより重要なのは、それはより速いのでしょうか?Python asyncioを使用してDataFrameをスライスしてループに保存することはできますか?

私が試したことは、このようなものです:

async def a_split(dist,df): 
    temp_df = df[df.district == dist] 
    await temp_df.to_csv('{}.csv'.format(d)) 

async def m_lp(df): 
    for dist in df.district.unique().tolist(): 
     await async_slice(dist,df) 

loop = asyncio.get_event_loop() 

loop.run_until_complete(m_lp(dfTotal)) 
loop.close() 

しかし、私は次のエラーを取得しています:

TypeError: object NoneType can't be used in 'await' expression 

それは私の試みから明白でなければ、私は非常に新しいですasyncioと私はそれがどのように動作するのか分からない。これが愚かな質問である場合はお詫び申し上げます。

asyncioがジョブの良いツールではない場合は、より良い方法がありますか?

編集:私の知る限りパンダ内のような何asyncioサポートはありません知っているように

--------------------------------------------------------------------------- 
TypeError         Traceback (most recent call last) 
<ipython-input-22-2bc2373d2920> in <module>() 
     2 loop = asyncio.get_event_loop() 
     3 
----> 4 loop.run_until_complete(m_lp(dfTotal)) 
     5 loop.close() 

C:\Users\5157213\AppData\Local\Continuum\Anaconda3\envs\python36\lib\asyncio\base_events.py in run_until_complete(self, future) 
    464    raise RuntimeError('Event loop stopped before Future completed.') 
    465 
--> 466   return future.result() 
    467 
    468  def stop(self): 

<ipython-input-20-9e91c0b1b06f> in m_lp(df) 
     1 async def m_lp(df): 
     2  for dist in df.district.unique().tolist(): 
----> 3   await a_split(dist,df) 

<ipython-input-18-200b08417159> in a_split(dist, df) 
     1 async def a_split(dist,df): 
     2  temp = df[df.district == dist] 
----> 3  await temp.to_csv('C:/Users/5157213/Desktop/Portfolio/{}.csv'.format(dist)) 

TypeError: object NoneType can't be used in 'await' expression 
+0

フルトレースバックを含めるには、質問をしてください(https://stackoverflow.com/posts/45154096/edit)。それが立っているので、私たちはそれを指すのを待っています。 – dirn

+0

編集済み - df.to_csv行の横に待機しているように見えますが、待たずに何も返されません – Greg

答えて

1

:以下

完全なトレースバック。私は、シングルスレッドのイベントベースのアーキテクチャは、負荷/大規模なデータで作業するための数十のオプションがあるシステムでは、最高のツールではないと思います。大きなデータセットの場合はdaskをご覧ください。

あなたがFuture(またはその他のawaitableオブジェクト)を返しますが、Noneしないawait機能Dataframe.to_csvしようとしたので、あなたが得るエラーです。

関連する問題