0

So I have a list of columns titles that I want to delete and saved them in a list called 'h'. I have given this list as input to the pandas.drop() function. But the function does not remove any columns.

h=['MinorOperatingSystemVersion', 'MinorSubsystemVersion', 'NumberOfSections', 'e_lfanew', 'SizeOfHeapReserve', 'SizeOfUninitializedData', 'BaseOfCode', 'SizeOfHeaders', 'SizeOfHeapCommit', 'SectionAlignment', 'FileAlignment', 'e_cp', 'e_cblp', 'e_minalloc', 'e_ovno', 'e_sp', 'e_cparhdr', 'e_maxalloc', 'e_lfarlc', 'NumberOfSymbols', 'NumberOfRvaAndSizes', 'PointerToSymbolTable', 'Magic', 'SizeOfOptionalHeader', 'Machine', 'e_ip', 'e_cs', 'e_oemid', 'e_csum', 'e_oeminfo', 'LoaderFlags', 'e_ss']

df_2=table.copy()
df_2.drop(columns=h)

print(df_2)
print(table) 


OUTPUT : 

      e_cblp  e_cp  e_cparhdr  e_minalloc  e_maxalloc  e_ss  e_sp  e_csum  \
0        144     3          4           0       65535     0   184       0   
1        144     3          4           0       65535     0   184       0   
2        144     3          4           0       65535     0   184       0   
3        144     3          4           0       65535     0   184       0   
4        144     3          4           0       65535     0   184       0   
...      ...   ...        ...         ...         ...   ...   ...     ...   
3883     144     3          4           0       65535     0   184       0   
3884     144     3          4           0       65535     0   184       0   
3885     144     3          4           0       65535     0   184       0   
3886     144     3          4           0       65535     0   184       0   
3887     144     3          4           0       65535     0   184       0   

      e_ip  e_cs  ...  CheckSum  Subsystem  DllCharacteristics  \
0        0     0  ...    115397          2               33792   
1        0     0  ...         0          2                   0   
2        0     0  ...         0          2                   0   
3        0     0  ...    142244          2               33088   
4        0     0  ...     60601          2                1024   
...    ...   ...  ...       ...        ...                 ...   
3883     0     0  ...   1169404          2               33792   
3884     0     0  ...   1891705          2                 320   
3885     0     0  ...     64132          2                  64   
3886     0     0  ...    148009          2                   0   
3887     0     0  ...   1792532          2                   0   

      SizeOfStackReserve  SizeOfStackCommit  SizeOfHeapReserve  \
0                1048576               4096            1048576   
1               10485760              40960            6291456   
2                1048576               4096            1048576   
3                 262144               8192            1048576   
4                1048576               4096            1048576   
...                  ...                ...                ...   
3883              262144               8192            1048576   
3884             1048576               4096            1048576   
3885             1048576               4096            1048576   
3886             1048576               4096            1048576   
3887             1048576               4096            1048576   

      SizeOfHeapCommit  LoaderFlags  NumberOfRvaAndSizes  class  
0                 4096            0                   16      1  
1                16384            0                   16      1  
2                 4096            0                   16      0  
3                 4096            0                   16      0  
4                 4096            0                   16      0  
...                ...          ...                  ...    ...  
3883              4096            0                   16      0  
3884              4096            0                   16      0  
3885              4096            0                   16      0  
3886              4096            0                   16      0  
3887              4096            0                   16      0  

[3888 rows x 52 columns]


      e_cblp  e_cp  e_cparhdr  e_minalloc  e_maxalloc  e_ss  e_sp  e_csum  \
0        144     3          4           0       65535     0   184       0   
1        144     3          4           0       65535     0   184       0   
2        144     3          4           0       65535     0   184       0   
3        144     3          4           0       65535     0   184       0   
4        144     3          4           0       65535     0   184       0   
...      ...   ...        ...         ...         ...   ...   ...     ...   
3883     144     3          4           0       65535     0   184       0   
3884     144     3          4           0       65535     0   184       0   
3885     144     3          4           0       65535     0   184       0   
3886     144     3          4           0       65535     0   184       0   
3887     144     3          4           0       65535     0   184       0   

      e_ip  e_cs  ...  CheckSum  Subsystem  DllCharacteristics  \
0        0     0  ...    115397          2               33792   
1        0     0  ...         0          2                   0   
2        0     0  ...         0          2                   0   
3        0     0  ...    142244          2               33088   
4        0     0  ...     60601          2                1024   
...    ...   ...  ...       ...        ...                 ...   
3883     0     0  ...   1169404          2               33792   
3884     0     0  ...   1891705          2                 320   
3885     0     0  ...     64132          2                  64   
3886     0     0  ...    148009          2                   0   
3887     0     0  ...   1792532          2                   0   

      SizeOfStackReserve  SizeOfStackCommit  SizeOfHeapReserve  \
0                1048576               4096            1048576   
1               10485760              40960            6291456   
2                1048576               4096            1048576   
3                 262144               8192            1048576   
4                1048576               4096            1048576   
...                  ...                ...                ...   
3883              262144               8192            1048576   
3884             1048576               4096            1048576   
3885             1048576               4096            1048576   
3886             1048576               4096            1048576   
3887             1048576               4096            1048576   

      SizeOfHeapCommit  LoaderFlags  NumberOfRvaAndSizes  class  
0                 4096            0                   16      1  
1                16384            0                   16      1  
2                 4096            0                   16      0  
3                 4096            0                   16      0  
4                 4096            0                   16      0  
...                ...          ...                  ...    ...  
3883              4096            0                   16      0  
3884              4096            0                   16      0  
3885              4096            0                   16      0  
3886              4096            0                   16      0  
3887              4096            0                   16      0  

[3888 rows x 52 columns]

As you can see both the dataframes contain same no of columns which is as if the columns were not removed.

1 Answers1

0

the drop function does not chnage value in place. hence the result needs to be saved into another variable.

 df_3=df_2.drop(columns=h) 

this worked for me !