and I wish to access elements 1:10 and 14. How is that done?
In python, with Numpy, I could do a[1:10,14]. Is there an accepted approach in Julia. Everything I tried has failed. I am also wanting to access non-contiguous columns in a Dataframe with 30 columns, say, columns 10:15 and 20:25.
In [16]: a = np.array(range(20))
In [17]: a[1:10, 14]
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-17-0de60f11d6ed> in <module>
----> 1 a[1:10, 14]
IndexError: too many indices for array
In [18]: a[range(0, 10), 14]
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-18-0c6926e5d9b3> in <module>
----> 1 a[range(0, 10), 14]
IndexError: too many indices for array
The thing that actually works for me in Python is also what I would recommend in Julia:
In a function signature, f(args...) accepts any number of function arguments, collecting them as a tuple named args.
When used elsewhere, args... takes a tuple (or actually any iterable at all) and expands it to the same number of positional arguments.
Here’s an example of doing both:
julia> function f(args...)
@show args
+(args...)
end
f (generic function with 1 method)
julia> f(1, 2)
args = (1, 2)
3
julia> f(1, 2, 3)
args = (1, 2, 3)
6
The function f takes any number of arguments. It receives them as a tuple named args. It then hands that tuple as multiple arguments to the function + (which also happens to take multiple arguments).
Thank you everybody!! I really thought this would work in Python, but I stand corrected.
I guess the issue was mixing slices with non-consecutive indexes. I appreciate the help
For accessing DataFrames columns you can also use various combinations of Regex, All , Between and Not. You can find examples of usage in DataFrames Tutorial, specifically working with columns notebook.