I have a dataframe:
id year value
a1 2020-K A
a1 2020-1 B
a1 2020-2 A
a1 2021-K A
a1 2021-7 C
a1 2022-K C
a1 2022-1 C
a1 2022-2 A
b1 2020-K D
b1 2020-1 C
b1 2020-2 A
b1 2021-K D
b1 2021-1 D
b1 2021-2 C
b1 2022-K C
b1 2022-1 B
b1 2022-2 A
I want to turn each unique value in "year" column into columns and put "values" in them. desired result is:
id 2020-K 2020-1 2020-2 2020-7 2021-K 2021-1 2021-2 2021-7 2022-K 2022-1 2022-2 2022-7
a1 A B A NaN A NaN NaN C C C A NaN
b1 D C A NaN D D C NaN C B A NaN
How could I do that? Is there any function for such transposing?