0

Below is the input data

Type   Cat       Var         Dist    Count
@joy   A1 + B1  x + y + z   0:25:75    4
.cet   C1 + D1  p + q       50:50      2
sam    E1 + F1  g           100:3:2    10

Below is the intended output

Type   Cat       Var         Dist    Count   Output
@joy   A1 + B1  x + y + z   0:25:75    4    @joyA1 + B1x + y +z
.cet   C1 + D1  p + q       50:50      2    .cetC1 + D1p + q
sam    E1 + F1  g           100:3:2    10    samE1 + F1g

Below is the try from my end:

df.iloc[:,0:3].dot(['Type','Cat','Var'])
Mata
  • 538
  • 3
  • 17
AB14
  • 397
  • 2
  • 13

3 Answers3

1

You can do that using

df['output'] = df['Type'].map(str) + df['Cat'].map(str) + df['Var].map(str)
Vishal A.
  • 1,373
  • 8
  • 19
0

you can simply use:

df['Output']=df['Type']+' '+df['Cat']+' '+df['Var']

output:

   Type      Cat        Var         Dist  Count                  output
0  @joy  A1 + B1  x + y + z  0.018229167      4  @joy A1 + B1 x + y + z
1  .cet  C1 + D1      p + q     50:50:00      2      .cet C1 + D1 p + q
2   sam  E1 + F1          g    100:03:02     10           sam E1 + F1 g
Gabriele
  • 333
  • 1
  • 7
0

Base R: Using paste0

df$Output <- paste0(df$Type, df$Cat, df$Var)
  Type     Cat       Var    Dist Count                 Output
1 @joy A1 + B1 x + y + z 0:25:75     4 @joy A1 + B1 x + y + z
2 .cet C1 + D1     p + q   50:50     2     .cet C1 + D1 p + q
3  sam E1 + F1         g 100:3:2    10          sam E1 + F1 g

OR

library(dplyr)
df %>% 
  mutate(Output = paste(Type, Cat, Var, sep = ""))
  Type     Cat       Var    Dist Count                 Output
1 @joy A1 + B1 x + y + z 0:25:75     4 @joy A1 + B1 x + y + z
2 .cet C1 + D1     p + q   50:50     2     .cet C1 + D1 p + q
3  sam E1 + F1         g 100:3:2    10          sam E1 + F1 g

OR:

library(tidyr)
df %>% 
  unite(Output, c(Type, Cat, Var), remove=FALSE)
                  Output Type     Cat       Var    Dist Count
1 @joy_A1 + B1_x + y + z @joy A1 + B1 x + y + z 0:25:75     4
2     .cet_C1 + D1_p + q .cet C1 + D1     p + q   50:50     2
3          sam_E1 + F1_g  sam E1 + F1         g 100:3:2    10
TarJae
  • 72,363
  • 6
  • 19
  • 66