Skip to content

Instantly share code, notes, and snippets.

@guidoschmidt
Created April 13, 2024 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guidoschmidt/f2b69193c05609f450a00a0ae49cd7ce to your computer and use it in GitHub Desktop.
Save guidoschmidt/f2b69193c05609f450a00a0ae49cd7ce to your computer and use it in GitHub Desktop.
asyncio Pandas dataframe
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())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment