Search code examples
pythonpandasexcel-automation

how to remove two columns in excel using pandas?


Sample data:

| | Unnamed: 0 | Status | Clarification Opened | Failed | |---|------------|-------------------------|----------------------|--------| | 1 | 1 | P0 Dry Run - 12/02/18 | | 2.0 | | 2 | 2 | P1 Test Plan - 06/02/18 | | 2.0 | | 3 | 3 | P2 Test plan - 03/01/18 | 2.0 | 21.0 | I need to know how to remove the unwanted first two columns and with the size of columns will vary


Solution

  • You need remove all columns witch not contains Unnamed - it means need all columns which not contains Unnamed:

    df = df.loc[:, ~df.columns.str.contains('Unnamed')]