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

Method random_split

dask/dataframe/dask_expr/_collection.py:1932–1968  ·  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

1930 return new_collection(self.expr.isna())
1931
1932 def random_split(self, frac, random_state=None, shuffle=False):
1933 """Pseudorandomly split dataframe into different pieces row-wise
1934
1935 Parameters
1936 ----------
1937 frac : list
1938 List of floats that should sum to one.
1939 random_state : int or np.random.RandomState
1940 If int or None create a new RandomState with this as the seed.
1941 Otherwise draw from the passed RandomState.
1942 shuffle : bool, default False
1943 If set to True, the dataframe is shuffled (within partition)
1944 before the split.
1945
1946 Examples
1947 --------
1948
1949 50/50 split
1950
1951 >>> a, b = df.random_split([0.5, 0.5]) # doctest: +SKIP
1952
1953 80/10/10 split, consistent random_state
1954
1955 >>> a, b, c = df.random_split([0.8, 0.1, 0.1], random_state=123) # doctest: +SKIP
1956
1957 See Also
1958 --------
1959 dask.DataFrame.sample
1960 """
1961 if not np.allclose(sum(frac), 1):
1962 raise ValueError("frac should sum to 1")
1963 frame = expr.Split(self, frac, random_state, shuffle)
1964
1965 out = []
1966 for i in range(len(frac)):
1967 out.append(new_collection(expr.SplitTake(frame, i, self.ndim)))
1968 return out
1969
1970 @derived_from(pd.DataFrame)
1971 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