Answers for "pandas sample rows"

1

pandas sample rows

# To sample a fixed number of rows
df.sample(n = 100)

# To sample a fraction of rows
df.sample(frac = 0.5)
Posted by: Guest on April-04-2021
0

pandas sample

>>> df = pd.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_seen
falcon         2          2                 10
dog            4          0                  2
spider         8          0                  1
fish           0          0                  8
Posted by: Guest on June-17-2020

Python Answers by Framework

Browse Popular Code Answers by Language