1

Here is what I have done:

df = pd.DataFrame(data={'in':[2, 2, 3, 4], 'out':[2,2,4,4]}) in_out=df.groupby(['in','out']).size() 

I got results:

in out 2 2 2 3 4 1 4 4 1 dtype: int64 

How do I turn the results into a dataframe with columns in, out and count?

1 Answer 1

1

Use reset_index with parameter name:

df = pd.DataFrame(data={'in':[2, 2, 3, 4], 'out':[2,2,4,4]}) in_out=df.groupby(['in','out']).size().reset_index(name='count') print in_out in out count 0 2 2 2 1 3 4 1 2 4 4 1 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.