0

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
  • 118,151
  • 13
  • 38
  • 75
Nastik
  • 43
  • 5

1 Answers1

1

You can try using pivot:

suicide_df.pivot(index=['country', 'year', 'sex'], columns='age', values='suicides_no').reset_index()
Mayank Porwal
  • 31,737
  • 7
  • 30
  • 50