I have a dataframe with 3 columns including A , B , C .i need to create columns using B,C columns as shown in the output section below.
dataframe:
A B C
C_1 pink 1971
C_1 pink 1972
C_1 blue 1972
C_1 red 1973
C_1 pink 1973
C_1 white 1974
output:
Here for the first row , the C year is 1971 which is the least one and b column count is 1 so for this row the output should be 1 for B_cnt_C-0 and further it should be 0 as we dont info before 1971 but for 2nd and 3rd row v have info for 1971 and 1972.so output should be as shown below for 2nd and 3rd row and same procedure for all remaining rows.
A B C B_cnt_C-0 B_cnt_C-1 B_cnt_C-2 B_cnt_C-3
C_1 pink 1971 1 0 0 0
C_1 pink 1972 2 1 0 0
C_1 blue 1972 2 1 0 0
C_1 red 1973 2 2 1 0
C_1 pink 1973 2 2 1 0
C_1 white 1974 1 2 2 1