如何解决:(已弃用;在将来的版本中,这将引发TypeError.在调用缩减之前,只选择有效的列.)?



我试图在df['total_income']列中填充空值,但我收到错误:

is deprecated; in a future version this will raise TypeError.  Select only valid columns before calling the reduction.

填写total_income的值基于用户的年龄、教育程度和收入类型,代码如下:

import pandas as pd
import numpy as np
df=pd.read_csv(r'C:UsersgabriDownloadscredit_scoring_eng.csv')

def fill_na(age_group, education, income_type):
for i in education:
for j in income_type:
for f in age_group:
df.loc[(df['total_income'].isna()) & (df['education']==i), 'total_income']=df.loc[(df['total_income'].isna())&(df['education']==i)&(df['income_type']==j)&(df['age_group']==f)].median()
return dff
df['total_income']=fill_na(df['age_group'], df['education'], df['income_type'])
print(df.sort_values(by='total_income', ascending=False).head(numeric_only=True))

我期望在总收入栏上填充缺失值,中值与特定类别的参数。

下面是错误信息:

Output exceeds the size limit. Open the full output data in a text editor
C:UsersgabriAppDataLocalTempipykernel_3088670034715.py:9: FutureWarning: Dropping of nuisance columns in DataFrame reductions (with 'numeric_only=None') is deprecated; in a future version this will raise TypeError.  Select only valid columns before calling the reduction.
df.loc[(df['total_income'].isna()) & (df['education']==i), 'dob_years']=df.loc[(df['total_income'].isna())&(df['education']==i)&(df['income_type']==j)&(df['age_group']==f)].median()
C:UsersgabriAppDataLocalTempipykernel_3088670034715.py:9: FutureWarning: Dropping of nuisance columns in DataFrame reductions (with 'numeric_only=None') is deprecated; in a future version this will raise TypeError.  Select only valid columns before calling the reduction.
df.loc[(df['total_income'].isna()) & (df['education']==i), 'dob_years']=df.loc[(df['total_income'].isna())&(df['education']==i)&(df['income_type']==j)&(df['age_group']==f)].median()

无限reapeting .

使用

.median(numeric_only=True)

不是

median()

DataFrame reduction (with 'numeric_only=None')已弃用;

,因为None是默认值

相关内容

最新更新