Skip to content

Instantly share code, notes, and snippets.

@guidoschmidt
Created April 13, 2024 20:07
Show Gist options
  • Save guidoschmidt/f2b69193c05609f450a00a0ae49cd7ce to your computer and use it in GitHub Desktop.
Save guidoschmidt/f2b69193c05609f450a00a0ae49cd7ce to your computer and use it in GitHub Desktop.

Revisions

  1. guidoschmidt created this gist Apr 13, 2024.
    14 changes: 14 additions & 0 deletions async_pandas_dataframe.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    import asyncio

    import numpy as np
    import pandas as pd

    async def fun2(x):
    return x * 2

    async def main():
    df = pd.DataFrame(np.arange(10), columns=['old'])
    df['new'] = await asyncio.gather(*(fun2(v) for v in df['old']))
    print(df)

    asyncio.run(main())