Skip to content
Advertisement

Combine all column elements except two particular columns

JavaScript

I want to combine the elements in all columns except two columns, ‘SourceFile’ and ‘Label’. I tried the above code. Which resulted in value error. There is so many columns. So I can’t use

JavaScript

Advertisement

Answer

col != ['SourceFile','Label'] is syntactically wrong and it gives NameError not the ValueError. First get the columns you don’t want and convert it to set.

JavaScript

Now get all columns as set:

JavaScript

Finally take the set difference and assign back as a list:

JavaScript

Now you can use aggregate method:

JavaScript

See the sample execution:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement