在Pandas列中查找混合类型 [英] Find mixed types in Pandas columns
本文介绍了在Pandas列中查找混合类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在解析数据文件时,我经常收到以下警告:
Ever so often I get this warning when parsing data files:
WARNING:py.warnings:/usr/local/python3/miniconda/lib/python3.4/site-
packages/pandas-0.16.0_12_gdcc7431-py3.4-linux-x86_64.egg/pandas
/io/parsers.py:1164: DtypeWarning: Columns (0,2,14,20) have mixed types.
Specify dtype option on import or set low_memory=False.
data = self._reader.read(nrows)
但是,如果数据很大(我有5万行),如何在数据中找到dtype发生变化的地方?
But if the data is large (I have 50k rows), how can I find WHERE in the data the change of dtype occurs?
推荐答案
我不确定您要做什么,但是很容易找到包含不共享第一个元素类型的元素的行排.例如:
I'm not entirely sure what you're after, but it's easy enough to find the rows which contain elements which don't share the type of the first row. For example:
>>> df = pd.DataFrame({"A": np.arange(500), "B": np.arange(500.0)})
>>> df.loc[321, "A"] = "Fred"
>>> df.loc[325, "B"] = True
>>> weird = (df.applymap(type) != df.iloc[0].apply(type)).any(axis=1)
>>> df[weird]
A B
321 Fred 321
325 325 True
这篇关于在Pandas列中查找混合类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文