I have a simple question about printing dataframe names. I apologize if this has already been asked - I searched but could not find an answer.
I sometimes work with Dataframes of 20+ columns, and I cannot remember the names of all the columns. In addition, I like to subset Dataframes for analysis. Thus, I like to print the column names with a colon and comma, to enable an easy copy and paste to subset a dataframe.
Currently, I use a comprehension for this purpose. But for ease of use, I would like to print from within a function. And when I try to print from within a function, I get an extra array of βNothingβ data that fills up the REPL. Is there a way to suppress the extra βNothingβ data from printing within a function?
Here is a MWE:
# generate 20-column dataframe
using DataFrames
df = DataFrame(col1 = rand(2), col2 = rand(2), col3 = rand(2), col4 = rand(2), col5 = rand(2), col6 = rand(2), col7 = rand(2), col8 = rand(2), col9 = rand(2), col10 = rand(2), col11 = rand(2), col12 = rand(2), col13 = rand(2), col14 = rand(2), col15 = rand(2), col16 = rand(2), col17 = rand(2), col18 = rand(2), col19 = rand(2), col20 = rand(2));
# Method 1 - print names without semicolon (produces printed names and 20-element Array{Nothing, 1})
[print(string(":", x, ", ")) for x in names(df)]
# Method 2 - print names with semicolon (produces printed names only)
[print(string(":", x, ", ")) for x in names(df)];
# Method 3 - use function (produces printed names and 20-element Array{Nothing, 1})
function dfnames(df::DataFrame)
[print(string(":", x, ", ")) for x in names(df)];
end
dfnames(df)
Thanks for any thoughts.