首页 > 解决方案 > 使用熊猫过滤 Excel 列

问题描述

我有 5 列,但我只想要列 A = Override 的行

A 列 B 列等... 覆盖 xxxx 矩阵 xxxx

正确过滤列 A 的正确语法是什么?

标签: pythonexcelpandasfilterautomation

解决方案


以下将删除名称与“覆盖”不同的列。

import pandas as pd

#read in dataframe
df = pd.read_excel(path_to_df)

cols_name = df.columns.tolist()
for col in cols_name:
    if df[col] is not df['Override']:
        del df[col]


推荐阅读