Access DataFrames index

I’m sure this a trivial task but I cannot find the answer. I have a Julia DataFrame and I’d like the index as an array, in pandas I can do:

>>> import pandas as pd
>>> df = pd.DataFrame([1,2,3,4,5])
>>> df.index
RangeIndex(start=0, stop=5, step=1)
>>> list(df.index)
[0, 1, 2, 3, 4]

How can I do this in Julia?

Or in Julia DataFrames can we only have range indices, making 1:length(df) the best option?

DataFrames.jl does not support row names currently (if this is what you are looking for). To get each row index use either 1:nrow(df) or axes(df, 1).

1 Like