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 as pd
conn = sqlite3.connect('factbook.db')
query = "select * from facts where area_land =0;"
facts = pd.read_sql_query(query,conn)
final = initial_pop*math.e**(growth_rate*35)
facts['pop2050'] = facts['population','population_growth'].apply(final_pop,axis=1)
Apply will pass you along the entire row with axis=1. Adjust like this assuming your two columns are called
def final_pop(row): return row.initial_pop*math.e**(row.growth_rate*35)