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

后端 未结 4 1765
刺人心
刺人心 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:32

    Apply will pass you along the entire row with axis=1. Adjust like this assuming your two columns are called initial_popand growth_rate

    def final_pop(row):
        return row.initial_pop*math.e**(row.growth_rate*35)
    

提交回复
热议问题