当前位置:网站首页>Valueerror: cannot take a larger sample than population when 'replace=false‘
Valueerror: cannot take a larger sample than population when 'replace=false‘
2022-06-24 22:17:00 【Dai Meng Ma】
Complete error report
ValueError: Cannot take a larger sample than population when 'replace=False'
resolvent
An error will be reported when the number of target samples is greater than the existing samples , You need to make your own judgment based on your business , For example, the following is a solution
import pandas as pd
import numpy as np
dataframe = pd.DataFrame(np.random.random(size=(10, 2)))
# Start sampling
sample_df = dataframe.sample(20) if dataframe.shape[0] > 20 else dataframe # If the number of samples exceeds some samples , Just go back , Otherwise, only return to 20 individual
print(sample_df.shape)
sample_df = dataframe.sample(6) if dataframe.shape[0] > 6 else dataframe
print(sample_df.shape)
Problem analysis
Using the following code will result in an error :
import pandas as pd
import numpy as np
dataframe = pd.DataFrame(np.random.random(size=(10, 2)))
dataframe.sample(20)
边栏推荐
- 是真干不过00后,给我卷的崩溃,想离职了...
- The profound meaning of unlimited ecological development in Poka -- Multidimensional Interpretation of parallel chain
- 代理模式详解
- 一个女孩子居然做了十年硬件。。。
- Structure du disque
- Publicity of the second batch of shortlisted enterprises! Annual Top100 smart network supplier selection
- 树莓派初步使用
- interrupt、interrupted 、isInterrupted 区别
- Want to be a test leader, do you know these 6 skills?
- linq查询集合类入门 案例武林高手类
猜你喜欢
随机推荐
Notes on writing questions (18) -- binary tree: common ancestor problem
Machine learning: gradient descent method
CV2 package guide times could not find a version that satisfies the requirement CV2 (from versions: none)
04A中断的配置
Balanced binary search tree
揭秘B站,程序员穿女装敲代码,效率更高是真的吗?
These map operations in guava have reduced my code by 50%
Learning notes 23-- basic theory of multi-sensor information fusion (Part I)
03--- antireflective film
leetcode-201_ 2021_ 10_ seventeen
波卡生态发展不设限的奥义——多维解读平行链
The profound meaning of unlimited ecological development in Poka -- Multidimensional Interpretation of parallel chain
L2 元年,Arbitrum Nitro 升级带来更兼容高效的开发体验
解决dataframe报错ValueError: Cannot take a larger sample than population when ‘replace=False‘
first-order-model实现照片动起来(附工具代码) | 机器学习
Flutter 库冲突问题解决
YGG 近期游戏合作伙伴一览
SAP interface debug setting external breakpoints
干货丨产品的可行性分析要从哪几个方面入手?
Practice of hierarchical management based on kubesphere







