How to apply custom function to pandas data frame for each row

后端 未结 4 1762
刺人心
刺人心 2021-02-02 11:09

I want to apply a custom function and create a derived column called population2050 that is based on two columns already present in my data frame.

import pandas          


        
4条回答
  •  后悔当初
    2021-02-02 11:25

    You were almost there:

    facts['pop2050'] = facts.apply(lambda row: final_pop(row['population'],row['population_growth']),axis=1)
    

    Using lambda allows you to keep the specific (interesting) parameters listed in your function, rather than bundling them in a 'row'.

提交回复
热议问题