Saturday, 15 May 2010

pandas - Native method to skip Nans in a lambda function? -



pandas - Native method to skip Nans in a lambda function? -

i wondering if there's native method skip nans in lambda function. have dataframe 'y' in form below. i'm attempting turn year column ints. lambda function breaks because of nan. i've come below, i'm wondering if there improve ways deal pervasive issue? thanks!

year 137 2005 138 nan

to deal it, used try/except. wonder if there' improve way deal nans.

def turn_int(x): try: homecoming int(x) except: homecoming np.nan y.year.apply(lambda x: turn_int(x))

int doesn't have representation of nan. normal way deal drop nan's first:

year = y.year.dropna().astype(int)

pandas nan

No comments:

Post a Comment