How to delete multiple columns from an SFrame?

User 3252 | 3/3/2016, 4:32:43 PM

Hi,

I am able to delete a single column from an SFrame using the del command: example del sf1['city'].

Question : How to delete multiple columns in one command? I tried to delete columns 'state' and 'country' from the same SFrame and got error.

``del sf1['state', 'country']  
   Throws KeyError: "Cannot find column ('state', 'country')"

``del sf1[{'state', 'country'}]
      Throws KeyError: "Cannot find column set(['state', 'country'])"

``del sf1['state']
       This works without errors.

I appreciate any help you can provide.

Comments

User 1359 | 3/4/2016, 7:45:10 PM

Hello,

Try the remove_columns method to remove any number of columns by label:

sf1 sf1.remove_columns(['state', 'country']) sf1 You should see that the columns have been removed from the SFrame.

https://dato.com/products/create/docs/generated/graphlab.SFrame.removecolumns.html#graphlab.SFrame.removecolumns


User 3252 | 3/6/2016, 10:12:07 PM

That command does it. Thank you.