0
I have a dataframe with 60 columns, but for the case need only 3
ID DT_DATE NR_PRICE
0 22828949 2019-02-26 453.00
1 22828949 2019-02-22 453.00
2 22828949 2019-02-18 453.00
3 22828949 2019-02-05 453.00
4 22828950 2019-02-26 189.00
5 22828950 2019-02-24 189.00
6 22828950 2019-02-19 189.00
7 22828950 2019-02-14 189.00
8 22828950 2019-02-01 411.05
I need to list the first date, penultimate and last date with their respective values I tried to do it this way:
def custom(series):
min_date = list(series)[0]
pen_date = list(series)[-2]
max_date = list(series)[-1]
return min_date,pen_date,max_date
def get_price(series):
price_a = list(series)[0]
price_c = list(series)[-2]
price_b = list(series)[-1]
return price_a,price_c,price_b
dfb=df.groupby(["ID"],as_index=False).agg({"DT_DATE":custom,"NR_PRICE":get_price})
When I run it, the following error msg appears
"IndexError: list index out of range"
Someone’s been through it?