-1

I have a dataframe - df

grouped = df.groupby('run')
s = grouped['chip'].value_counts()

then I get this, a series

What I have:

enter image description here

What I want is:

enter image description here

So I am guessing if I can change those series into columns then everything will be good. any ideas? Help needed thank you!

Anurag Dabas
  • 23,866
  • 9
  • 21
  • 41

1 Answers1

1

Try via unstack(),rename(),rename_axis() and reset_index() method:

s=(s.unstack(level=1)
    .rename(columns=lambda x:'chip'+str(x))
    .rename_axis(columns=None)
    .reset_index())
Anurag Dabas
  • 23,866
  • 9
  • 21
  • 41
  • Are you a genius?? – steve workspace Jun 18 '21 at 05:00
  • @steveworkspace nope btw if it solves your query then you can try considering accepting this answer(click on the tick to make it green) to indicate others that the issue is solved...Thnx ***:)*** – Anurag Dabas Jun 18 '21 at 05:19
  • but I think it's not same @KarnKumar – Anurag Dabas Jun 18 '21 at 05:34
  • 1
    @AnuragDabas, its not same but it has nearby same approach [this may be helpful](https://stackoverflow.com/questions/54863165/pandas-dataframe-to-convert-the-unique-value-as-column-name) , i appreciate your help though +1 – Karn Kumar Jun 18 '21 at 05:37