Split based on factors alternative of R function in python

koneru nikhil
   df = 
    v1  v2
    ds  43
    ds  34
    ds  32
    foo 34
    foo 32

In R we can create list of dataframes using

h = split(df,as.factor(df$v1))
output
h:
[[1]]
v1   v2
ds   43
ds   34
ds   32
[[2]]
v1   v2
foo  34
foo  32

What is the alternative for creating list of dataframes based upon different values in single column in python

i tried groupby in python but the answer which i am getting is different

df = df.groupby('v1').groups
Psidom

You can use:

h = [g for _, g in df.groupby('v1')]

to get a list of data frames.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Fast alternative to split in R

From Dev

Python equivalent of R "split"-function

From Dev

R: `split` preserving natural order of factors

From Dev

Split R dataframe by n number of factors

From Dev

R: `split` preserving natural order of factors

From Dev

Alternative to assign function in r

From Dev

How to create summaries of subgroups based on factors in R

From Dev

R - Find rows based on group factors

From Dev

Split a string based on "^" in R

From Dev

Applying a mathematical function to a list of factors in python

From Dev

Python alternative to R Markdown

From Dev

Split POS tagged textvectors/factors into sentences with R - regex

From Dev

Python regex based split

From Dev

Python regex based split

From Dev

python's shlex.split alternative for Go

From Dev

Split and Diff function in R

From Dev

Prime Factors, Alternative to Diamond Brackets

From Dev

Unsplit reduced data table based on two factors in R

From Dev

shuffle one column based upon factors in another R

From Dev

Extract rows from R data frame based on factors (strings)

From Dev

R Creating new columns based on factors in another column

From Dev

Unsplit reduced data table based on two factors in R

From Dev

Iterative subtraction based on factors in a data frame using R

From Dev

R: Creating multiple resampled dataset based on multiple factors

From Dev

R Split a column based on pattern

From Dev

Split string in R based on punctuation

From Dev

Confusion with split function in Python

From Dev

Python .split() function

From Dev

Python complicated split function