Skip to content
g21589 edited this page Feb 22, 2020 · 18 revisions

Pandas

https://medium.com/bigdatarepublic/advanced-pandas-optimize-speed-and-memory-a654b53be6c2

Async I/O

import asyncio, nest_asyncio
nest_asyncio.apply() # Fix asyncio bug in IPython (RuntimeError: This event loop is already running)

async def example1(): # 定義一個中間會被中斷的協程
    print("Start example1 coroutin.")
    await asyncio.sleep(1) # 中斷協程一秒
    print("Finish example1 coroutin.")

async def example2(): # 定義一個協程
    print("Start example2 coroutin.")
    # do some process...
    print("Finish example2 coroutin.")

tasks = [
    asyncio.ensure_future(example1()),
    asyncio.ensure_future(example2()),
]
    
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.wait(tasks))

Clone this wiki locally