【问题标题】:Drop columns that contain a specific value in Pandas删除包含 Pandas 中特定值的列
【发布时间】:2023-02-17 19:23:06
【问题描述】:

任何人都知道为什么结果不同? 两个数据帧具有相同的数据类型(float64)

我期待 [0] 作为这两项任务的输出。

【问题讨论】:

标签: python pandas dataframe


【解决方案1】:

您可以使用:

list_C = []
cols = df.columns
for i in cols:
    a = df[i].str.count("0.5").sum()
    if a > 0:
        list_C.append(i)


print(list_C)
df = df.drop(list_C, axis=1)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-17
    • 2014-10-29
    • 2018-08-18
    • 2023-03-19
    • 2013-10-04
    • 1970-01-01
    相关资源
    最近更新 更多