culebrón
culebrón

Reputation: 36453

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

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

Upvotes: 1

Views: 482

Answers (1)

Nils Gudat
Nils Gudat

Reputation: 13800

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.

Upvotes: 2

Related Questions