python中Sample函数是什么?

Python (169) 2023-06-23 10:37:02

本文教程操作环境: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

输出结果:

这里大家也可以自己自行带入需要抽取的列表,参考代码进行调用哦~那么接下来,就套用代码,尝试下吧~

THE END

发表回复