python中Sample函数是什么?

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

python中Sample函数

1、在Pandas中进行数据分析,能够随机选取若干个行或列,做列表的抽取;

2、函数参数有:frac、replace、weights、random_state和axis。

函数作用:

随机选取若干个行或列。

函数用法:

DataFrame.sample(n=None,frac=None,replace=False,weights=None,random_state=None,axis=None)

函数参数:

frac、replace、weights、random_state、axis

实例演示:

随机抽取5行。

sample1=df.sample(n=5)
sample1

输出结果:

python中Sample函数是什么?

发表回复