Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
slice per group
#2
You need to decide where these groups will be stored, in a list, or you want concatenate them into new data-frame?

import pandas as pd
# generate sample data
df = pd.DataFrame({'factor': pd.np.random.choice(range(5), 1000), 'value':pd.np.random.rand(1000)})\

#groups
dfs = [df.loc[v[:50]] for g, v in df.groupby('factor').groups.items()]
Reply


Messages In This Thread
slice per group - by Progressive - Jul-19-2019, 12:48 PM
RE: slice per group - by scidam - Jul-19-2019, 01:07 PM
RE: slice per group - by Progressive - Jul-19-2019, 01:50 PM
RE: slice per group - by scidam - Jul-20-2019, 06:52 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Inserting slice of array objects into different slice ThemePark 4 2,554 Apr-01-2020, 01:10 PM
Last Post: ThemePark
  TypeError: '(slice(None, None, None), 0)' is an invalid key zaki424160 1 15,234 Jul-17-2019, 11:53 PM
Last Post: scidam
  Melt or Slice Grin 0 2,186 Jun-24-2018, 06:02 PM
Last Post: Grin
  How to group variables & check correlation of group variables wrt single variable SriRajesh 2 2,978 May-23-2018, 03:01 PM
Last Post: SriRajesh

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020