'concatenate two columns values pandas
I have a dataframe data :
Cluster OsId BrowserId PageId VolumePred ConversionPred
255 7 11 17 1149582 4.0
607 18 99 16 917224 8.0
22 0 12 14 1073848 4.0
I would like to add new column "OSBROWSER" which is the concatenation of two columns : OsId and BrowserId.
The result should be like this :
Cluster OsId BrowserId PageId VolumePred ConversionPred OSBROWSER
255 7 11 17 1149582 4.0 (7, 11)
607 18 99 16 917224 8.0 (18, 99)
22 0 12 14 1073848 4.0 (0, 12)
I try like this :
data['OSBrowser'] = data["OsId"] + data["BrowserId"]
But it gave me the sum of the two clumns values
Any idea please? thanks you
SOLUTION :
data['OSBrowser'] = list(zip(data.OsId, data.BrowserId))
Solution 1:[1]
This is a possible solution:
data['OSBrowser'] = data[["OsId", "BrowserId"]].apply(tuple, axis=1)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Riccardo Bucco |
