1

So This is the dataframe.

enter image description here

the attribute 'age' has 6 discrete values, therefore I want to add 6more columns which holds values from attribute 'suicides_no". and removing 'age' attribute. So the final DF will look like:

Albania 1987  female    0    14    4    6    0     1
Albania 1987   male     0    21    9    16   1     1

Note: Taking suicides_no.values and reshaping it won't help as the total entries are not divisible by 6

Andrej Kesely
  • 168,389
  • 15
  • 48
  • 91
Nastik
  • 53
  • 5

1 Answers1

2

You can try using pivot:

suicide_df.pivot(index=['country', 'year', 'sex'], columns='age', values='suicides_no').reset_index()
Mayank Porwal
  • 33,470
  • 8
  • 37
  • 58