groupby and list

In [1]: df = pd.DataFrame( {'a':['A','A','B','B','B','C'], 'b':[1,2,5,5,4,6]})
        df

Out[1]: 
   a  b
0  A  1
1  A  2
2  B  5
3  B  5
4  B  4
5  C  6

In [2]: df.groupby('a')['b'].apply(list)
Out[2]: 
a
A       [1, 2]
B    [5, 5, 4]
C          [6]
Name: b, dtype: object

In [3]: df1 = df.groupby('a')['b'].apply(list).reset_index(name='new')
        df1
Out[3]: 
   a        new
0  A     [1, 2]
1  B  [5, 5, 4]
2  C        [6]

4.11
13
Maurycy 90 points

                                    values = set(map(lambda x:x[1], mylist))
newlist = [[y[0] for y in mylist if y[1]==x] for x in values]

4.11 (9 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
python groupby list of lists groupby then chart python group by python dataframe pandas groupby explained groupby and where get group list by group pandas List.GroupByFunction. groupby by function group by and to list python do a group by on list groupby python string using groupby pandas groupby and column to list .group by pyhton list item group by python given a list group by a value df.groupby() python groupby function group by pytohn groupby values to list python group functions in python how to use groupby function in python how may group a list in python groupe by python groupby real python what does .groupby() return groupby a column pandas groupby lists in pandas what is the groupbykry in python ? using groupby how to use groupby.all in python pandas groupby a column and list groupby and order by python how to do groupby in python using a function groupby list python python .group(1) groupby function in pandas group by in graphene python group in list group by in python pandas groupby python3 python functions for groupby groupby pandas on list pandas groupby function groupby attribute in python groupby with and clause python what does group by does in python python group() group by python example groupby pandas list group by in python python .group() groupby pandas python Groupby functions in Python Why is .groupby() operation used groupby all df group function python pandas groupby category group(1) python groupby org python functions in groupby python groupby based on a column pandas groupby in python pandas group by to list group by function in python pandas python df groupby groupby a column in pandas python list group by df.groupby python what does groupby do in pandas dataframe groupby example python group list by value group by values in list python py list make group by group elements in list python group method in python _.groupBy() groupby methods groupby documentation group by in python example group by list pandas example group list elements python groupby where what is groupby in pandas groupby in python and create a list of groupby groupby operations python group list of list groupby example group list in dataframe python groupby in python list use groupby pandas groupby() group by in pyto python groupby(). groupby python example pandas group by list contents pandas groupbyx group by list. python group by list function group by in python group list items python Python group list elements group a list in npython .groupby in pandas python groupby filter group by phython group by python list groupby methods pandas group by in pytho group by in a list python group in list python python pandas groupby list groupyby in pandas group by to dataframe with list group by with list dataframe select group of list python group by function in pandas _.groupBy( python groupby describe python group items in list pandas groupby by pandas groupby in a groupby groupby function dataframe df.groupby() what it returns groupby list pandas group by in python group by to dataframe python list group by funciton group by i pythin groupby dataframe in python pandas groupby column and grouper groupby pandas group method python how to use group by in python function groupby python groupby command pandas groupby and orderby example groupby function in python group by list item in python groupby dataframe python group function in python groupby pd groupby syntax python groupby in pandas python grouper group list groupby list .group in python df groupby .group() python .group method in python python groupby example pandas groupby column groupby value in list python groupby function python Groupby in Python 3 dataframe groupby groupby in python string how to group a list in python groupby pandas example groupby to list what does groupby()[] does groupby functions python groupby into list python group by function python groupby into list when we use groupby in python group method on python where and groupby groupby by function in pytohn df.groupby in python how to use groupby in python groupby python list groupby to list pandas group in python group by in to list groupby in python list grouper python python group by value list python group list groupby dataframe pandas groupby group by to list pandas group a list in python group a list python group by value in list python python groupby Grouper group by function in Python group by in python list .groupby() python .groupby python group() python groupby function explained how to use groupby in pandas group items in list python python group list values how to group a list df.groupby group by() python group python groupby to dataframe can we use group by in list python groupby groupby get dataframe using groupby in pandas pandas groupby list python groupby to list groupby pandas groupby and form list pandas groupby function list group by python group all groupby functions python how to groupby in python dataframe groupby list how to list a column in pandas group y groupby and list group array by value python python group list elements by value group by python groupby python group by in python python group list elements by two python group by list python group value list python list group by grouping in list python python group by
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source