MCPcopy Create free account
hub / github.com/dask/dask / random_split

Method random_split

dask/dataframe/dask_expr/_collection.py:1966–2002  ·  view source on GitHub ↗

Pseudorandomly split dataframe into different pieces row-wise Parameters ---------- frac : list List of floats that should sum to one. random_state : int or np.random.RandomState If int or None create a new RandomState with this as the seed.

(self, frac, random_state=None, shuffle=False)

Source from the content-addressed store, hash-verified

1964 return new_collection(self.expr.isna())
1965
1966 def random_split(self, frac, random_state=None, shuffle=False):
1967 """Pseudorandomly split dataframe into different pieces row-wise
1968
1969 Parameters
1970 ----------
1971 frac : list
1972 List of floats that should sum to one.
1973 random_state : int or np.random.RandomState
1974 If int or None create a new RandomState with this as the seed.
1975 Otherwise draw from the passed RandomState.
1976 shuffle : bool, default False
1977 If set to True, the dataframe is shuffled (within partition)
1978 before the split.
1979
1980 Examples
1981 --------
1982
1983 50/50 split
1984
1985 >>> a, b = df.random_split([0.5, 0.5]) # doctest: +SKIP
1986
1987 80/10/10 split, consistent random_state
1988
1989 >>> a, b, c = df.random_split([0.8, 0.1, 0.1], random_state=123) # doctest: +SKIP
1990
1991 See Also
1992 --------
1993 dask.DataFrame.sample
1994 """
1995 if not np.allclose(sum(frac), 1):
1996 raise ValueError("frac should sum to 1")
1997 frame = expr.Split(self, frac, random_state, shuffle)
1998
1999 out = []
2000 for i in range(len(frac)):
2001 out.append(new_collection(expr.SplitTake(frame, i, self.ndim)))
2002 return out
2003
2004 @derived_from(pd.DataFrame)
2005 def round(self, decimals=0):

Callers 2

test_random_partitionsFunction · 0.80
test_random_partitionsFunction · 0.80

Calls 2

new_collectionFunction · 0.90
sumFunction · 0.50

Tested by 2

test_random_partitionsFunction · 0.64
test_random_partitionsFunction · 0.64