Find mixed types in Pandas columns

前端 未结 3 2038
闹比i
闹比i 2020-12-25 15:06

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_gdcc         


        
3条回答
  •  Happy的楠姐
    2020-12-25 16:02

    In addition to DSM's answer, with a many-column dataframe it can be helpful to find the columns that change type like so:

    for col in df.columns:
        weird = (df[[col]].applymap(type) != df[[col]].iloc[0].apply(type)).any(axis=1)
        if len(df[weird]) > 0:
            print(col)
    

提交回复
热议问题