bigframes.geopandas.GeoSeries.sample#
- GeoSeries.sample(n:int|None=None,frac:float|None=None,*,random_state:int|None=None,sort:bool|Literal['random']|None='random')→Series#
Return a random sample of items from an axis of object.
You can userandom_state for reproducibility.
Examples:
>>>importbigframes.pandasasbpd>>>df=bpd.DataFrame({'num_legs':[2,4,8,0],...'num_wings':[2,0,0,0],...'num_specimen_seen':[10,2,1,8]},...index=['falcon','dog','spider','fish'])>>>df num_legs num_wings num_specimen_seenfalcon 2 2 10dog 4 0 2spider 8 0 1fish 0 0 8[4 rows x 3 columns]
Fetch one random row from the DataFrame (Note that we userandom_stateto ensure reproducibility of the examples):
>>>df.sample(random_state=1) num_legs num_wings num_specimen_seendog 4 0 2[1 rows x 3 columns]
A random 50% sample of the DataFrame:
>>>df.sample(frac=0.5,random_state=1) num_legs num_wings num_specimen_seendog 4 0 2fish 0 0 8[2 rows x 3 columns]
Extract 3 random elements from the Seriesdf[‘num_legs’]:
>>>s=df['num_legs']>>>s.sample(n=3,random_state=1)dog 4fish 0spider 8Name: num_legs, dtype: Int64
- Parameters:
n (Optional[int],default None) – Number of items from axis to return. Cannot be used withfrac.Default = 1 iffrac = None.
frac (Optional[float],default None) – Fraction of axis items to return. Cannot be used withn.
random_state (Optional[int],default None) – Seed for random number generator.
sort (Optional[bool|Literal["random"]],default "random") –
‘random’ (default): No specific ordering will be applied aftersampling.
’True’ : Index columns will determine the sample’s order.
’False’: The sample will retain the original object’s order.
- Returns:
A new object of same type as caller containingn items randomlysampled from the caller object.
- Return type:
- Raises:
ValueError – If both
nandfracare specified.