Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

sample datafra,e PYTHON

# divide your data by 2 
df.sample(frac=0.5, replace=True, random_state=1)
Comment

sample data frame in python

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 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

PREVIOUS NEXT
Code Example
Python :: how to remove some lines border from plt plot 
Python :: docx change font python 
Python :: check if anything in a list is in a string python 
Python :: how to return an html file in flask 
Python :: python - count values that contain special characters 
Python :: python unlist flatten nested lists 
Python :: pause python 
Python :: except python 
Python :: append to pandas dataframe 
Python :: python float to 2 decimals 
Python :: cool things to do with python 
Python :: redirect stdout to variable python 
Python :: python raise and exit 
Python :: python get string from decimal 
Python :: convert string to dictionary python 
Python :: make blinking text python1 
Python :: OS Error: Connection refused, errno = 111, address = 127.0.0.1, port = 43350 
Python :: add column array python 
Python :: how to change turtle shape in python 
Python :: how to read xlsx file in jupyter notebook 
Python :: factorial in python 
Python :: series.Series to dataframe 
Python :: transpose array python 
Python :: drop a row with a specific value of a column 
Python :: numpy initialize 2d array 
Python :: pandas export csv without index 
Python :: python sort two key 
Python :: python sorted dictionary multiple keys 
Python :: how to get input python 
Python :: tkinter text blurry 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =