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

空列:对象是“浮动”并且没有 len()

如何解决空列:对象是“浮动”并且没有 len()

但运行此代码我试图过滤它读取的文件,其中一个过滤器是:

如果文件有 'SOURCE' 列,则:如果 lambda len().max() 'SOURCE' 列 > 0,我们可以得出结论不为空,然后按照 代码...

但是!!如果“SOURCE”列是空的,它告诉我一个“浮点数”,因此它没有错误形式的长度。我只是想过滤:如果“SOURCE”列是空的,不是逐行而是整列,那么就这样做...

for f in files_xlsx:
wb = load_workbook(input_path + "\\" + f,read_only=True)
if 'New Leads' in wb.sheetnames:
    df = pd.read_excel(input_path + "\\" + f,sheet_name="New Leads")
    colre = [col for col in df.columns]
    for eo in colre:
        df.rename(columns={eo: eo.replace('*','').replace('**','') for eo in colre})
    dtcol = [col for col in df.columns if "Date" in col]
    for ex in dtcol:
        df.rename(columns={ex: "Activity Date"},inplace=True)
    cols = df.columns
    if "SOURCE" in cols:
        if df.dtypes['SOURCE'] != 'float':
            if df.soURCE.map(lambda x: len(x)).max() > 0:
                df.dropna(how = 'all')
                df['File'] = f
                df_xlsx = pd.concat([df,df_xlsx],ignore_index=True)
                df_xlsx = df_xlsx[["Email","SOURCE","File","Activity Date"]]
            else:
                df_ns = df_ns.append([f],ignore_index=True)
        else:
            df_ns = df_ns.append([f],ignore_index=True)
    else:
        df_ns = df_ns.append([f],ignore_index=True)
else:
    df_ns = df_ns.append([f],ignore_index=True)

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