join dataframe columns

94 views
Skip to first unread message

pip7...@gmail.com

unread,
Feb 28, 2015, 5:35:01 PM2/28/15
to julia...@googlegroups.com
Hi
How can I join 2 columns in a dataframe.

e.g.
Dataframe 1

Row    Name       Name2       Amt
1         Test        A               123
2         Test2      B                456
etc

I want to be able to join Name and Name2 and use a separator like -
eg
Row    Name       Amt
1         Test-A     123
2         Test2-B    456

Regards

Johan Sigfrids

unread,
Mar 1, 2015, 9:50:42 AM3/1/15
to julia...@googlegroups.com
With a DataFrame like:

df = DataFrame(Name = ["Test", "Test2"], Name2 = ["A", "B"], Amt=[123,456])

you could do something like this:

df[:Name] = map((x,y) -> string(x, -, y), df[:Name], df[:Name2])

Note that you will still have the Name2 column.

pgs

unread,
Mar 2, 2015, 6:47:16 AM3/2/15
to julia...@googlegroups.com
Johan
Thanks for this.
I also found that I could use .* to join two columns in a DataFrame.
Using a dot star to join! -  I found surprising - but it worked.
Regards
Reply all
Reply to author
Forward
0 new messages