1

I had a dataframe and I applied the groupby method. Now I have a pandas.core.groupby.SeriesGroupBy but I cant use any of the dataframe methods onto it. How can I convert it to a usable dataframe?

type(survivor)
pandas.core.groupby.SeriesGroupBy

by applying .groups it looks like this:

{'C': Int64Index([  1,   9,  19,  26,  30,  31,  34,  36,  39,  42,
         847, 849, 852, 858, 859, 866, 874, 875, 879, 889],
        dtype='int64', name=u'ID', length=168),
'Q': Int64Index([  5,  16,  22,  28,  32,  44,  46,  47,  82, 109, 116, 126, 
143,
         156, 171, 186, 188, 196, 198, 208, 214, 241, 245, 260, 264, 274,
         727, 749, 767, 768, 776, 778, 787, 790, 825, 828, 885, 890],
        dtype='int64', name=u'ID'),
'S': Int64Index([  0,   2,   3,   4,   6,   7,   8,  10,  11,  12,
         877, 878, 880, 881, 882, 883, 884, 886, 887, 888],
        dtype='int64', name=u'ID', length=644)}

I have tried following the instructions of some other questions related but still get the same error(for example): AttributeError: 'SeriesGroupBy' object has no attribute 'set_index'

thanks a lot!

1 Answer 1

2

You can convert the pandas.core.groupby.SeriesGroupBy to a DataFrame very simply as follows:

survivor.apply(pd.DataFrame)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.