How do I sample()
a row from a Dataframe, without its index?
If there is a different approach, that's ok.
Pandas documentation offers ignore_index
parameter.
DataFrame.sample(n=None, frac=None, replace=False, weights=None, random_state=None, axis=None, ignore_index=False)
However, when I run:
df['col'].sample(ignore_index=True)
I'll still get the index and the value, e.g.:
1 value
Desired:
value
CodePudding user response:
In pandas all objects like Series
and DataFrame
s has index.
Parameter ignore_index
obviously generate default RangeIndex, not remove it.
If need scalar from Series
select first value:
out = df['col'].sample(1).iat[0]