def qt_sub(val, first):
    year_dif = val[0:4] - first[0:4]
qt_dif = val[6] - first[6]
return 4 * int(year_dif) + int(qt_dif)
alldata['diff_from_first'] = alldata.apply(lambda x: qt_sub(x[
    'Year_Quarter'], x['First_Sale']), axis=1)
Find first time a value occurs in the dataframe