How to get row number and make it another column in DataFrames in Julia?

308 Views Asked by At

I need to inner-join 2 dataframes: routes and sources. Joining should be on routes.source=sources.row number. And I don't see how to do it (in Python/Pandas you'd just do right_index=True). I've checked the DataFrames.jl doc, and can't see how to join on row number. Nor I could convert row number into another column.

Routes:

Routes, source number in column "source"

Sources:

Sources, source number is row number

1

There are 1 best solutions below

0
Nils Gudat On BEST ANSWER

A DataFrame does not have a row index, unlike e.g. a pandas DataFrame.

If you want to join on the row number, you can just create it as a column:

sources.row_num = 1:nrow(sources)

and then

innerjoin(routes, sources, on = :source => :row_num)

to perform an inner join where the source column of routes and the row_num column of sources are used to perform the join.