pandas 名称错误:未定义名称'resample'

5ktev3wc  于 2022-12-21  发布在  其他
关注(0)|答案(2)|浏览(393)

我尝试在python中使用resample方法,但收到以下错误:

---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-22-9ff5896e97a3> in <module>
----> 1 df_no_default_downsampled=resample(df_no_deafult,replace=False,n_samples=1000,random_state=42)
      2 df_default_downsampled=resample(df_deafult,replace=False,n_samples=1000,random_state=42)

NameError: name 'resample' is not defined
2w3kk1z5

2w3kk1z51#

您似乎需要DataFrame.sample

df_no_default_sampled=df_no_deafult.sample(replace=False,n=1000,random_state=42)
vwhgwdsa

vwhgwdsa2#

你要做的简单事情就是从sklearn导入resample

from sklearn.utils import resample
df_no_default_downsampled = resample(df_no_deafult, replace = False, n_samples = 1000, random_state = 42)

相关问题