i have following data frame
df = pd.dataframe({'a':[74.75, 91.71, 145.66], 'b':[4, 3, 3], 'c':[25.34, 33.52, 54.70]}) b c 0 74.75 4 25.34 1 91.71 3 33.52 2 145.66 3 54.70
i create column df['d'] list or series first 3 columns suitable use in column np.irr function this
d 0 [ -74.75, 2.34, 25.34, 25.34, 25.34] 1 [ -91.71, 33.52, 33.52, 33.52] 2 [-145.66, 54.70, 54.70, 54.70]
so this
df['e'] = np.irr(df['d'])
i did far this
[-df.a[0]]+[df.c[0]]*df.b[0]
but not quite there.
do need column 'd'
?
by way can add as:
df['d'] = [[-df.a[i]]+[df.c[i]]*df.b[i] in xrange(len(df))] df['e'] = df['d'].map(np.irr)
if don't need it, can directly set e
df['e'] = [np.irr([-df.a[i]]+[df.c[i]]*df.b[i]) in xrange(len(df))]
or:
df['e'] = df.apply(lambda x: np.irr([-x.a] + [x.c] * x.b), axis=1)
Comments
Post a Comment