Python pandas: remove everything after a delimiter in a string

前端 未结 4 746
隐瞒了意图╮
隐瞒了意图╮ 2020-12-01 03:00

I have data frames which contain e.g.:

"vendor a::ProductA"
"vendor b::ProductA"
"vendor a::Productb"

I need to

4条回答
  •  感动是毒
    2020-12-01 03:24

    If it is in a specific column (having name: column) of a data frame (having name: dataframe), you can also use

    dataframe.column.str.replace("(::).*","")
    

    It gives you the below result

             column        new_column       
    0  vendor a::ProductA  vendor a
    1  vendor b::ProductA  vendor b
    2  vendor a::Productb  vendor a
    

    By using this you need not specify any position, as it gets rid of anything present after '::'

    I guess this might come oh help,Good luck!

提交回复
热议问题