python3 types_Python3:解决DtypeWarning: mixed types.

问题

pandas读入数据时,出现如下数据类型warning

DtypeWarning: Columns (0) have mixed types. Specify dtype option on import or set low_memory=False.

exec(code_obj, self.user_global_ns, self.user_ns)

这会导致后续在DataFrame中检索数据失败,例如df['col'].isin(['abcde'])输出为空。

方法

法1:

按照提示,读入数据时指定参数low_memory=False,可以部分解决这类问题。

How exactly does low_memory=False fix the problem?

It reads all of the file before deciding the type, therefore needing more memory.

法2:

为出现混合类型(mixed types)的列,指定类型。

首先,根据“Columns (0) have mixed types”可以判断是columns[0]出现混合类型;

然后,进行如下设定:

In [68]: df_temp = df_temp.astype({df_temp.columns[0]: str})

In [68]: df_temp[df_temp['record_index']=='201904290059392698']

Out[68]:

record_index p_id ... eqp_id operator_id

28772 201904290059392698 940071C2B01 ... ECR03 39091876

[1 rows x 7 columns]

查询成功。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值