Hi, When im working with some big dataframes and I need to create some columns based on functions. So i have some code like this

Def function(row): function

And then I run the function on the df as

df[‘new column’] = df.apply(function, axis=1)

But I do this with 10 or more columns/functions at time. I don’t think this is efficient because each time a column is created it had to parce the entire data frame. There’s a way to create all the columns at the same time while parsing the rows only once?

Thanks for any help.

  • snakedrake@lemmy.world
    link
    fedilink
    arrow-up
    5
    ·
    11 months ago

    Then change your function to operate across the dataframe and return a different dataframe?

    You can add multiple columns at the same time or do a merge statement of some kind