pandas.DataFrame.sample
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的更多相关文章
- pandas.DataFrame.sample随机抽样
https://study.163.com/course/courseMain.htm?courseId=1006383008&share=2&shareId=400000000398 ...
- Pandas Dataframe增、删、改、查、去重、抽样基本操作
总括 pandas的索引函数主要有三种: loc 标签索引,行和列的名称 iloc 整型索引(绝对位置索引),绝对意义上的几行几列,起始索引为0 ix 是 iloc 和 loc的合体 at是loc的快 ...
- pandas.DataFrame学习系列1——定义及属性
定义: DataFrame是二维的.大小可变的.成分混合的.具有标签化坐标轴(行和列)的表数据结构.基于行和列标签进行计算.可以被看作是为序列对象(Series)提供的类似字典的一个容器,是panda ...
- pandas.DataFrame的pivot()和unstack()实现行转列
示例: 有如下表需要进行行转列: 代码如下: # -*- coding:utf-8 -*- import pandas as pd import MySQLdb from warnings impor ...
- pandas DataFrame apply()函数(1)
之前已经写过pandas DataFrame applymap()函数 还有pandas数组(pandas Series)-(5)apply方法自定义函数 pandas DataFrame 的 app ...
- pandas DataFrame apply()函数(2)
上一篇pandas DataFrame apply()函数(1)说了如何通过apply函数对DataFrame进行转换,得到一个新的DataFrame. 这篇介绍DataFrame apply()函数 ...
- 把pandas dataframe转为list方法
把pandas dataframe转为list方法 先用numpy的 array() 转为ndarray类型,再用tolist()函数转为list
- pandas DataFrame.shift()函数
pandas DataFrame.shift()函数可以把数据移动指定的位数 period参数指定移动的步幅,可以为正为负.axis指定移动的轴,1为行,0为列. eg: 有这样一个DataFrame ...
- pandas DataFrame applymap()函数
pandas DataFrame的 applymap() 函数可以对DataFrame里的每个值进行处理,然后返回一个新的DataFrame: import pandas as pd df = pd. ...
随机推荐
- Windows 10 Shell命令
可以在[win+R] run 窗口 和 explorer窗口中使用 在command prompt中使用: C:\Users\a>explorer shell:sendto “ shell:Ac ...
- Ubuntu 18.04 截图工具 Shutter(可以标记重点)-安装及使用
Shutter 是一个功能丰富的屏幕截图程序.您可以屏幕的某个特定区域.特定的窗口. 或者是整个屏幕,甚至一整个网站截图.可以对截图应用各种效果,标记重点,然后上 传到一个图片托管网站——所有的任务在 ...
- nessus 安装
下载安装包: https://www.tenable.com/downloads/nessus 下载插件: https://docs.tenable.com/nessus/Content/Downlo ...
- 排序算法五:随机化快速排序(Randomized quicksort)
上一篇提到,快速排序的平均时间复杂度是O(nlgn),比其他相同时间复杂度的堆排序.归并排序都要快,但这是有前提的,就是假定要排序的序列是随机分布的,而不是有序的.实际上,对于已经排好的序列,如果用快 ...
- Docker 换源
近几天又折腾起 docker来了 我发现自己在拉镜像的时候,总是超时 然后百度了一下 说要换源 90sec的一个水友 推荐了我 阿里云的加速源 我看了还是免费就想试一下 讲一下过程 ...
- tensorflow 之Dataset数据集之批量数据
###生成批次数据 import tensorflow as tf '''reapt()生成重复数据集 batch()将数据集按批次组合''' file_name = ['img1','img2',' ...
- 常用jQuery技巧总结
1.关于页面元素的引用 通过jquery的$()引用元素包括通过id.class.元素名以及元素的层级关系及dom或者xpath条件等方法,且返回的对象为jquery对象(集合对象),不能直接调用do ...
- Codeforces 1114B (贪心)
题面 传送门 分析 答案很好看出,显然是选最大的m*k个数 那么如何构造方案呢 我们把最大的m*k个数的位置标记为1,其他标记为0 从左到右维护一个ptr,记录有标记的数的个数,如果当前有m个有标记的 ...
- 【主机管理项目】-(models.py(一对多、多对多数据库创建代码))
# -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import models class U ...
- topic模式下的收发
生产者: import pika import sys connection = pika.BlockingConnection(pika.ConnectionParameters( host='lo ...