Reputation: 149
I want to create random DataFrame with positive numbers only.
This is my code:
import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.randn(5, 4),
index=pd.date_range('1/1/2012', periods=5),
columns=['Alpha', 'Beta', 'Gamma', 'Delta'])
print (df)
My DataFrame looks like this:
Alpha Beta Gamma Delta
2012-01-01 0.817239 0.004713 -0.661963 -0.464963
2012-01-02 -2.255352 -0.064958 0.646194 -0.952761
2012-01-03 0.164314 0.177159 -1.618655 0.210663
2012-01-04 -0.231917 -0.627284 1.722947 -0.497787
2012-01-05 -0.214804 0.952356 0.816623 -1.576765
Upvotes: 1
Views: 1109
Reputation: 50573
np.random.rand()
produces a uniform distribution between 0 and 1.
Create an array of the given shape and populate it with random samples from a uniform distribution over
[0, 1)
.
For a 5x4 uniform distribution array between 1 to 10,
np.random.rand(5,4)*9+1
If you just want integers between 1(incl) and 10(excl)
np.random.randint(1,10,(5,4))
Upvotes: 5