Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas sample

>>> df['num_legs'].sample(n=3, random_state=1)
fish      0
spider    8
falcon    2
Name: num_legs, dtype: int64
Comment

pd df sample

df['num_legs'].sample(n=3, random_state=1)
Comment

pandas create sample dataframe

>>> import pandas as pd
>>> sentence = 'The quick brown fox jumps over a lazy dog.'
>>> words = sentence.split(' ')
>>> df1 = pd.DataFrame({'key': range(len(words)),
...                     'column1_Words': words,
...                     'column2_Length': [len(x) for x in words]
...                     })
>>> df1
   key column1_Words  column2_Length
0    0           The               3
1    1         quick               5
2    2         brown               5
3    3           fox               3
4    4         jumps               5
5    5          over               4
6    6             a               1
7    7          lazy               4
8    8          dog.               4
>>> 
Comment

pandas df sample frac

df.sample(frac=0.5, replace=True, random_state=1)
Comment

pandas sample frac

df.sample(frac=0.5, replace=True, random_state=1)
      num_legs  num_wings  num_specimen_seen
dog          4          0                  2
fish         0          0                  8
Comment

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
Comment

pandas sample

# Extract 10% of your dataframe
df.sample(frac=0.1, replace=True, random_state=1)
Comment

PREVIOUS NEXT
Code Example
Python :: how to create background images in tkinter 
Python :: pandas concat 
Python :: python script restart 
Python :: list comprehension python if else 
Python :: fill missing values with 0 
Python :: python logging to syslog linux 
Python :: pandas count number of rows with value 
Python :: how to run python file from cmd 
Python :: python print error output 
Python :: tkinter pack grid and place 
Python :: Setting Up Stylesheet Django 
Python :: python check if string in string 
Python :: python return number of characters in string 
Python :: python async await run thread 
Python :: python print n numbers 
Python :: python to run excel macro 
Python :: list deep copy 
Python :: python generate pdf from template 
Python :: filter dict by list of keys python 
Python :: fibonacci sequence in python using whileloop 
Python :: how to change int to four decimal places in python 
Python :: how to make a leaderboard in python 
Python :: crawl a folder python 
Python :: split stringg to columns python 
Python :: how to make a dict from a file py 
Python :: neural network hyperparameter tuning 
Python :: convert string to lowercase in python 
Python :: queryset to list python 
Python :: TypeError: Can only append a dict if ignore_index=True 
Python :: pandas order dataframe by index of other dataframe 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =