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

n : int, optional
Number of items from axis to return. Cannot be used with frac. Default = 1 if frac = None.
frac : float, optional
Fraction of axis items to return. Cannot be used with n.
replace : boolean, optional
Sample with or without replacement. Default = False.
weights : str or ndarray-like, optional
Default ‘None’ results in equal probability weighting. If passed a Series, will align with target object on index. Index values in weights not found in sampled object will be ignored and index values in sampled object not in weights will be assigned weights of zero. If called on a DataFrame, will accept the name of a column when axis = 0. Unless weights are a Series, weights must be same length as axis being sampled. If weights do not sum to 1, they will be normalized to sum to 1. Missing values in the weights column will be treated as zero. inf and -inf values not allowed.
random_state : int or numpy.random.RandomState, optional
Seed for the random number generator (if int), or numpy RandomState object.
axis : int or string, optional
Axis to sample. Accepts axis number or name. Default is stat axis for given data type (0 for Series and DataFrames, 1 for Panels).

Axis参数的意思是,从哪个维度取样。如axis = 0,即从row中取样。

pandas.DataFrame.sample的更多相关文章

  1. pandas.DataFrame.sample随机抽样

    https://study.163.com/course/courseMain.htm?courseId=1006383008&share=2&shareId=400000000398 ...

  2. Pandas Dataframe增、删、改、查、去重、抽样基本操作

    总括 pandas的索引函数主要有三种: loc 标签索引,行和列的名称 iloc 整型索引(绝对位置索引),绝对意义上的几行几列,起始索引为0 ix 是 iloc 和 loc的合体 at是loc的快 ...

  3. pandas.DataFrame学习系列1——定义及属性

    定义: DataFrame是二维的.大小可变的.成分混合的.具有标签化坐标轴(行和列)的表数据结构.基于行和列标签进行计算.可以被看作是为序列对象(Series)提供的类似字典的一个容器,是panda ...

  4. pandas.DataFrame的pivot()和unstack()实现行转列

    示例: 有如下表需要进行行转列: 代码如下: # -*- coding:utf-8 -*- import pandas as pd import MySQLdb from warnings impor ...

  5. pandas DataFrame apply()函数(1)

    之前已经写过pandas DataFrame applymap()函数 还有pandas数组(pandas Series)-(5)apply方法自定义函数 pandas DataFrame 的 app ...

  6. pandas DataFrame apply()函数(2)

    上一篇pandas DataFrame apply()函数(1)说了如何通过apply函数对DataFrame进行转换,得到一个新的DataFrame. 这篇介绍DataFrame apply()函数 ...

  7. 把pandas dataframe转为list方法

    把pandas dataframe转为list方法 先用numpy的 array() 转为ndarray类型,再用tolist()函数转为list

  8. pandas DataFrame.shift()函数

    pandas DataFrame.shift()函数可以把数据移动指定的位数 period参数指定移动的步幅,可以为正为负.axis指定移动的轴,1为行,0为列. eg: 有这样一个DataFrame ...

  9. pandas DataFrame applymap()函数

    pandas DataFrame的 applymap() 函数可以对DataFrame里的每个值进行处理,然后返回一个新的DataFrame: import pandas as pd df = pd. ...

随机推荐

  1. PHP RSA公私钥的理解和示例说明

    1.生成公钥和私钥 要应用RSA算法,必须先生成公钥和私钥,公钥和私钥的生成可以借助openssl工具.也可以用在线生成公私钥.(网站:http://web.chacuo.net/netrsakeyp ...

  2. 刷leetcode之路

    写的不是很好,仅记录自己所写的,仅供参考. 第七题: Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = ...

  3. java微信扫码支付Native(模式二)

    官方开发文档模式二的地址:https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_5 pom文件的依赖: <?xml versio ...

  4. POI样式

    5.POI样式 在Excel应用中,会需要用到各种样式,包括单元格背景色.边框.高度.宽度.内容相对位置.字体格式.字体大小.字体颜色等等.POI提供了一系列的样式,能满足我们一般开发中的需求. 5. ...

  5. R 保存包含中文的 eps 图片--showtext

    来自统计之都,感谢 Ihavenothing(http://cos.name/cn/profile/81532) 详情参考:http://cos.name/cn/topic/151358?replie ...

  6. spring4.1.8扩展实战之八:Import注解

    spring4.1.8扩展实战之八:Import注解 2018年09月10日 12:53:57 博陵精骑 阅读数:441更多 所属专栏: spring4源码分析与实战    版权声明:欢迎转载,请注明 ...

  7. HTML-字符实体,平方米(㎡)m²

    转载自:https://blog.csdn.net/hangGe0111/article/details/80983250

  8. Git004--版本回退

    Git--版本回退 本文来自于:https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/ ...

  9. vue 数组中嵌套的对象添加新属性--页面更新

    vue 数组中嵌套的对象添加新属性--页面更新:https://www.jianshu.com/p/8f0e5bb13735

  10. UML类图及类之间关系

    1.UML基本介绍 UML:统一建模语言,是一种用于软件系统分析和设计的语言工具 2.UML图 UML图分类: 用例图 静态结构图:类图,对象图,包图,组件图,部署图 动态行为图:交互图,状态图,活动 ...