Equivalent of Paste R to Python

后端 未结 8 697
忘掉有多难
忘掉有多难 2021-02-01 14:32

I am a new python afficionado. For R users, there is one function : paste that helps to concatenate two or more variables in a dataframe. It\'s very useful. For example Suppose

8条回答
  •  礼貌的吻别
    2021-02-01 15:09

    This very much works like Paste command in R: R code:

     words = c("Here", "I","want","to","concatenate","words","using","pipe","delimeter")
     paste(words,collapse="|")
    

    [1]

    "Here|I|want|to|concatenate|words|using|pipe|delimeter"

    Python:

    words = ["Here", "I","want","to","concatenate","words","using","pipe","delimeter"]
    "|".join(words)
    

    Result:

    'Here|I|want|to|concatenate|words|using|pipe|delimeter'

提交回复
热议问题