数据清洗踩坑记

df1 = pd.read_csv(save_csv_path,header=0)
# print(type(df1))
# print(df1.columns)
# print(df1.count)
df1 = df1.sample(frac=1)
# print(df1.count())
# print(df1.drop_duplicates(['company_name','revoke_prob']).count())###pandas的dataframe的去重函数,不是sql下的distinct()!!!
<class 'pandas.core.frame.DataFrame'>
id                   4665042
create_time          4665042
update_time          4665042
company_name         4665042
revoke_prob          4665042
is_revoke            4665042
risk_score           4665042
rank                 4665042
original_industry    4665042
big_hy_code          4595134
big_hy_name          4655513
sub_rank             4665042
risk_type            4665042
dtype: int64
id                   4665024
create_time          4665024
update_time          4665024
company_name         4665024
revoke_prob          4665024
is_revoke            4665024
risk_score           4665024
rank                 4665024
original_industry    4665024
big_hy_code          4595116
big_hy_name          4655495
sub_rank             4665024
risk_type            4665024
dtype: int64

可以看出,去重前和去重后不同字段名称的数量不一样,查看pandas.count()源码,发觉这是因为

def count(self, axis='major'):
        """
        Return number of observations over requested axis.

        Parameters
        ----------
        axis : {'items', 'major', 'minor'} or {0, 1, 2}

        Returns
        -------
        count : DataFrame
        """
        i = self._get_axis_number(axis)

        values = self.values
        mask = np.isfinite(values)
        result = mask.sum(axis=i, dtype='int64')

        return self._wrap_result(result, axis)
再看np.isfinite()函数的定义,以及示例,可以看出,几种会判定为False的情况,不会计数!
Examples
    --------
    >>> np.isfinite(1)
    True
    >>> np.isfinite(0)
    True
    >>> np.isfinite(np.nan)
    False
    >>> np.isfinite(np.inf)
    False
    >>> np.isfinite(np.NINF)
    False
    >>> np.isfinite([np.log(-1.),1.,np.log(0)])
    array([False,  True, False])

    >>> x = np.array([-np.inf, 0., np.inf])
    >>> y = np.array([2, 2, 2])
    >>> np.isfinite(x, y)
    array([0, 1, 0])
    >>> y
    array([0, 1, 0])
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值