python - 空列:对象是 'float' 并且没有 len()
问题描述
Bu运行此代码我试图过滤它读取的文件,其中一个过滤器是:
如果文件有 'SOURCE' 列,则:如果 'SOURCE' 列的 lambda len().max() > 0,我们可以断定它不为空,然后按照代码...
但!!如果'SOURCE'列是空的,它告诉我这是一个'float',因此它没有错误形式的长度。我只是想过滤:如果'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)
解决方案
推荐阅读
- javascript - React 功能组件:基于状态值启用/禁用按钮
- typescript - 将 NestJs 上的参数值更改为另一个现有类
- jquery - jquery 验证不适用于我的 laravel 项目
- abap - 通过字段符号更改 IDoc 段 SDATA?
- sql - SQL - 转义字符串 (ORACLE DB)
- webpack - Webpack css-loader 没有处理 css,尽管配置似乎没问题
- shopware - Shopware 6:使用手动分配时产品滑块数据为空
- ruby-on-rails - rswag 规范(Rails)中的验证传入参数(在::body 中)
- java - 变量birthDate 可能没有被初始化......但我以为我做到了?
- javascript - 如何从异步函数中获取数据,它将返回“[object Promise]”而不是数据