1条回答 默认 最新
- ShowMeAI 2022-12-07 01:04关注
在使用 Pandas 的 DataFrame 时,如果出现错误信息 TypeError: You cannot set both the how and thresh arguments at the same time.,一般是因为在调用 DataFrame.dropna() 函数时,同时设置了 how 和 thresh 参数。
该错误的原因是,DataFrame.dropna() 函数中的 how 参数和 thresh 参数不能同时使用。how 参数用于指定丢弃缺失值的方法,可以设置为 'any'、'all' 或其他值;thresh 参数用于指定每行或每列最少需要保留多少个非空值,如果超过指定的阈值则保留该行或列,否则丢弃该行或列。
为了避免上述错误,在使用 DataFrame.dropna() 函数时,只能设置其中的一个参数。例如,如果要使用 how 参数来丢弃缺失值,可以这样调用该函数:
df.dropna(how='any')
如果要使用 thresh 参数来丢弃缺失值,可以这样调用该函数:
df.dropna(thresh=3)
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用 1