0

I am struggling to find the error in my code.

code:

import pandas as pd

dic = {2011: 170, 2012: 200, 2013: 300}

data = [[2012, 10], [2013, 30], [2014, 14]]
  
df = pd.DataFrame(data, columns=['year', 'age'])

def create_d(year, age):
    if age<18:
        d = 0
    else:
        d=dic[year]
        return d

df["d"] =  create_d(df.year, df.age)

and this is the error I receive. Could someone pls help me interpret it? Thank you.

Error:

 ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
mozway
  • 194,879
  • 13
  • 39
  • 75
Stata_user
  • 562
  • 3
  • 14

0 Answers0