-2

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

2 Answers2

1

Let's use this:

# import excel
df = pd.read_excel('file_name.xlsx', sheet_name='Sheet1')
# remove columns
df.drop(axis=1, labels=list_with_column_name_to_remove, inplace=True)
# save excel
writer = pd.ExcelWriter('file_name.xlsx')
df.to_excel(writer,'Sheet1')
writer.save()
CezarySzulc
  • 1,849
  • 1
  • 14
  • 30
1

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')]
Kenly
  • 24,317
  • 7
  • 44
  • 60
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252