小编yas*_*hul的帖子

理解python中的df.isnull.mean()

我有一个数据框 df。代码是这样写的

df.isnull().mean().sort_values(ascending = False)

这是输出的一部分-

inq_fi                                 1.0
sec_app_fico_range_low                 1.0
Run Code Online (Sandbox Code Playgroud)

我想了解它是如何工作的?

如果我们使用,df.isnull()只有它会为每个单元格返回 True 或 False。如何mean()给我们正确的输出。我的目标是在所有列中找到空值的百分比。以上输出代表 inq_fi 和 sec_app_fico_range_low 具有所有缺失值。

我们也没有通过 sort_values 吗?

python python-3.x pandas

4
推荐指数
1
解决办法
3558
查看次数

减少python中的循环时间

python中的循环花了很多时间给出结果.这包含大约100k记录.

这需要很多时间.时间如何减少

df['loan_agr'] = df['loan_agr'].astype(int)

for i in range(len(df)):

    if df.loc[i,'order_mt']== df.loc[i,'enr_mt']:

        df['new_N_Loan'] = 1

        df['exist_N_Loan'] = 0

        df['new_V_Loan'] = df['loan_agr']

        df['exist_V_Loan'] = 0

    else:        

        df['new_N_Loan'] = 0

        df['exist_N_Loan'] = 1

        df['new_V_Loan'] = 0

        df['exist_V_Loan'] = df['loan_agr']
Run Code Online (Sandbox Code Playgroud)

python dataframe python-3.x pandas

1
推荐指数
1
解决办法
145
查看次数

标签 统计

pandas ×2

python ×2

python-3.x ×2

dataframe ×1