分析列中的混合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 (将#修改为@)