Pandas 奇技淫巧
程序员文章站
2022-07-14 20:03:55
...
1 随机采样 df.sample
df.sample(frac=0.06) # 随机取样(分数 四舍五入)
df.sample(frac=0.05) # 109*0.05=5.45 109*0.06=6.54
frac : float, optional
Fraction of axis items to return. Cannot be used withn
.
df.sample(n=5) # 5行
n : int, optional
Number of items from axis to return. Cannot be used withfrac
.
Default = 1 iffrac
= None.