Select 列基于 != 条件
Select columns based on != condition
我有一个数据框,我有一个列表,其中包含一些与数据框相对应的列名。如何过滤数据框,使其 != 列名列表,即我想要指定列表之外的数据框列。
我尝试了以下方法:
quant_vair = X != true_binary_cols
但得到输出错误:无法强制转换为系列,长度必须为 545:给定 155
奋斗了几个小时,我们将不胜感激。
它会帮助:
df.drop(columns = ["col1", "col2"])
您可以 drop
数据框中的列,或者创建一个不包含所有这些列的列表:
df_filtered = df.drop(columns=true_binary_cols)
或者:
filtered_col = [col for col in df if col not in true_binary_cols]
df_filtered = df[filtered_col]
我有一个数据框,我有一个列表,其中包含一些与数据框相对应的列名。如何过滤数据框,使其 != 列名列表,即我想要指定列表之外的数据框列。
我尝试了以下方法:
quant_vair = X != true_binary_cols
但得到输出错误:无法强制转换为系列,长度必须为 545:给定 155
奋斗了几个小时,我们将不胜感激。
它会帮助:
df.drop(columns = ["col1", "col2"])
您可以 drop
数据框中的列,或者创建一个不包含所有这些列的列表:
df_filtered = df.drop(columns=true_binary_cols)
或者:
filtered_col = [col for col in df if col not in true_binary_cols]
df_filtered = df[filtered_col]