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. 使用随机森林实现OSM路网城市多车道信息提取

    Multilane roads extracted from the OpenStreetMap urban road network using random forests.,DOI:10.111 ...

  2. 1207D Number Of Permutations

    题目大意 给你n个二元组 问你有几种排列是的按两个关键字中的任意一个都不是不降排列的 分析 不妨容斥 我们先加上总的方案数$n!$ 之后我们按第一个关键字排序 因为值相同的情况下不影响答案 所以让总方 ...

  3. 协议-网络-WebDev:WebDec 百科

    ylbtech-协议-网络-WebDev:WebDec 百科 WebDAV (Web-based Distributed Authoring and Versioning) 一种基于 HTTP 1.1 ...

  4. 127、TensorFlow 计算图执行(二)

    import tensorflow as tf # Define a placeholder that expects a vector of three floating-point values ...

  5. delphi 神经网络 学习

    https://github.com/uldercarrilho/ParallelNeuralNetwork

  6. mysql-M-S-S模型 中继器 级联

    1.基础环境 三台虚机并且安装有mysql 并且同步好数据库 2.主服务器-创建账号并授权 mysql> create user 'mslave'@'X.X.X.X' identified by ...

  7. stl vector创建二维数组

    vector<vector<); for (auto it = v.begin(); it != v.end(); it++) { ; (*it).reserve();//预留空间为5,但 ...

  8. error LNK2019: unresolved external symbol __vsnwprintf

    老DX SDK,新VS2019问题,编译老项目GG,依赖库加入 legacy_stdio_definitions.lib 解决

  9. 微信小程序这一块(上)

    1.根目录下面的文件: 凡是以app开头的都是全局配置文件 app.js 全局逻辑文件 注册小程序 app.json 全局配置文件 https://developers.weixin.qq.com/m ...

  10. oracle函数与存储方法

    oracle中的函数, 可以理解为java中的方法 有参数, 或者没有参数 通过return返回一个值 oracle存储过程跟函数唯一的区别, 存储过程不能通过return返回一个值 参数的类型, i ...