3

In the wikibook documentation it is said that delete! can be applied to a set of columns, but I am not able to get it, in order to delete several columns by name in a single passage.

I did tried also using list comprehension, but I still got an error (while for multiple dataframes only it works):

[delete!(df, :colname) for df in [df1, df2, df3], colname in ["col2","col5"]];

Any hint?

Antonello
  • 6,092
  • 3
  • 31
  • 56

2 Answers2

0

well, it seems that writing on SO gave me the inspiration:

[delete!(df, colname) for df in [df1, df2, df3], colname in [:col2,:col5]];

or

[delete!(df,[:col2,:col5]) for df in [df1, df2, df3]];

(I still have to understand what this strange : symbol means in Julia, my fault.. ;-) )

Antonello
  • 6,092
  • 3
  • 31
  • 56
  • 1
    When used in front of a letter, it denotes that that item is a symbol. Packages like DataFrames use symbols to denote column names rather than strings (aka "a"). If used in a situation like `a[1,:]` the `:` represents the concept of all, so this would return every column in the first row. – Alejandro Braun Feb 20 '17 at 21:37
0

As you found out, dataframes uses a symbol (:foo) instead of a string ("foo") to index a column. The explanation of why it is that way is given by one of the creators of the language here: https://stackoverflow.com/a/23482257/4746618

Community
  • 1
  • 1
favba
  • 175
  • 7
  • Very interesting discussion. It vaguely resembles me the C pointers and C `*` operator.. Thank you to pointing me to that. – Antonello Nov 28 '16 at 08:38