0

Below is just a snippet. I started with 28 columns, and dropped and number of them down to 13. Once I reduce my dataframe I would like to give all of the columns proper names.

Do I need to redim the dataframe after removing the columns?

data_xls.drop('DTM02', axis=1)
data_xls.drop('TDS01', axis=1)
data_xls.drop('CAD05', axis=1)
data_xls.drop('CAD07', axis=1)
data_xls.drop('REFX1', axis=1)

data_xls.columns = ['INV_NO','PO_NO','SHIP_TO','SHIP_ADD_1','SHIP_ADD_2','SHIP_CITY','SHIP_ZIP','INV_QTY','PART_NO','PO_NO','BL_NO','BLUE_BIN_Y_N', 'SHIP_LOC']

ValueError: Length mismatch: Expected axis has 28 elements, new values have 13 elements

chris clifton
  • 133
  • 1
  • 13

1 Answers1

2

DataFrame.drop() doesn't change DF in place. So you either need to assign it back or to use inplace=True

You can do it in one step:

cols_to_drop = ['DTM02','TDS01',...]
data_xls = data_xls.drop(cols_to_drop, axis=1)
MaxU - stand with Ukraine
  • 205,989
  • 36
  • 386
  • 419