0

code

df_cuenta.head

I have this dataset that simulates a company that sells financial products. I want to go through each row and create a new column that would be the summatory of the columns entry_date and dias_en_cartera. This column is called last_time_active.

I also want to create another column(boolean) called active_now that tells me if the day on last_time_active is smaller than today.

for index, row in df_cuenta.iterrows():
    last_date= row['entry_date'] + timedelta(days=row['días_encartera'])
    df_cuenta.insert(16,"last_date_active", last_date)
    if row['last_time_active']<now:
        df_cuenta.insert(17,"active_now", 0)
    else:
        df_cuenta.insert(17,"active_now", 1)    

df columns info

desertnaut
  • 52,940
  • 19
  • 125
  • 157
Leo
  • 1
  • 1
  • Does this answer your question? [Adding new column to existing DataFrame in Python pandas](https://stackoverflow.com/questions/12555323/adding-new-column-to-existing-dataframe-in-python-pandas) – John Nyingi Jul 06 '21 at 08:24

0 Answers0