random.rand是随机生成范围为(0,1)的数据,如下:
import numpy as np
import pandas as pd
import random
>>> s=pd.DataFrame(np.random.rand(5,4))
>>> s
0 1 2 3
0 0.344855 0.516473 0.853975 0.564404
1 0.661606 0.436078 0.303183 0.587708
2 0.777793 0.165298 0.692870 0.448780
3 0.968614 0.197588 0.813489 0.906796
4 0.363128 0.069430 0.021099 0.883420
random.randn是生成服从标准正太分布的数据,如下:
>>> s=pd.DataFrame(np.random.randn(5,4))
>>> s
0 1 2 3
0 -0.984862 -1.721127 -0.678430 0.298101
1 -0.712040 -0.399124 0.069610 -0.182591
2 0.203461 1.703491 0.186007 1.054380
3 -0.662301 -0.517859 0.346317 -0.176508
4 0.342412 1.180823 0.102282 1.677619
>>>
random.randint则是生成指定范围与个数内的整数,如下:
>>> s=pd.Series(np.random.randint(0,7,size=10))
>>> s
0 1
1 4
2 1
3 5
4 4
5 6
6 5
7 4
8 4
9 1
dtype: int32