微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

分析列中的混合dtype

如何解决分析列中的混合dtype

我在某些数据帧上做了一些merge,另存为csv,然后,最终的数据集有很多列。通过分析这些列,我意识到其中一些具有混合dtype。

我试图创建任何def函数来遍历所有列,并发现它是否发生在其他列上(逐列)。我做了,但是结果似乎是“ nonetype”对象。我无法将def的结果放入变量并视为表格。

我的输出

  1. 合并表格后(来自kaggle的olist挑战),我保存了.to_csv('namedoc.csv',index = False)

  2. 打开的文件 csv

  3. 然后我运行了以下代码

df['customer_zip_code_prefix'].map(type).value_counts()

<class 'int'>    101617
<class 'str'>     16384
Name: customer_zip_code_prefix,dtype: int64
  1. 然后我创建def
def hasmix_0(df):
    
    coluna_lista = df.columns.tolist()
    
    for cada in coluna_lista:
        
        print(df[cada].map(type).value_counts())
  1. def hasmix_0的结果按列显示所有结果,但这只是一个视图(我在下面放了一些示例)。实际上,我想创建一种更好的可视化方式(例如放入数据框)
<class 'str'>      117998
<class 'float'>         3
Name: customer_id,dtype: int64
<class 'str'>    118001
Name: customer_unique_id,dtype: int64
<class 'int'>    101617
<class 'str'>     16384
Name: customer_zip_code_prefix,dtype: int64
<class 'str'>      117998
<class 'float'>         3
Name: customer_city,dtype: int64
<class 'str'>      117998
<class 'float'>         3
Name: customer_state,dtype: int64
<class 'float'>    118001
Name: geolocation_zip_code_prefix,dtype: int64
<class 'float'>    118001
Name: geolocation_lat,dtype: int64

我读到一些NaN值变成浮点数,但是我提到的例子并非如此。我想验证在merge之后是否可能犯了任何错误

如何将结果转换为表/数据框?

先谢谢大家

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。