Hi,
Using Julia 1.8.1, VS Code notebooks
Entering the code from 4.1.2 Excel, I tried running:
path = write_grades_xlsx() xf = readxlsx(path)
which gave:
MethodError: objects of type Vector{String} are not callable
Use square brackets [] for indexing an Array.
Stacktrace:
[1] write_xlsx(name::String, df::DataFrame)
@ Main ~/julia-test/juliadatascience-dataframes.ipynb:4
[2] write_grades_xlsx()
@ Main ~/julia-test/juliadatascience-dataframes.ipynb:3
[3] top-level scope
@ ~/julia-test/juliadatascience-dataframes.ipynb:1
Here's the function:
function write_xlsx(name, df::DataFrame) path = "$name.xlsx" data = collect(eachcol(df)) cols = names(df) writetable(path, data, cols) end
I found that because you had defined a "names" variable earlier in the chapter, this clobbered the "names()" function. When I changed this to use Base.names(), everything worked properly. (Somewhat ironically, you mentioned the global variable problem just after defining "names". ;-))
I'd recommend just renaming "names" to something less ambiguous, and then it won't break the code below.
Thanks for the great work!
Ari