Creating a Column of Random Numbers in a DataFrame

Python
Data Preprocessing

 1|  import numpy as np
 2|  
 3|  # creates a column of random decimal numbers between 0 and 1
 4|  df['random'] = np.random.rand(len(df),1)
 5|  
 6|  # creates a column of random integers between 10 and 30
 7|  df['random_integer'] = np.random.randint(low=10, high=30, size=len(df))
1 Upvote
Tags: Rand | Randint
Did you find this snippet useful?

Sign up to bookmark this in your snippet library

Normalize Windowed Time Series
Python
Data Preprocessing

Scaler | Normalize | Scale | Min-max

4
Pivoting Pandas Dataframes
Python
Data Preprocessing

Pandas

3