Created
April 13, 2024 20:07
-
-
Save guidoschmidt/f2b69193c05609f450a00a0ae49cd7ce to your computer and use it in GitHub Desktop.
asyncio Pandas dataframe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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