jjzjj

ProductA

全部标签

python Pandas : remove everything after a delimiter in a string

我有数据框,其中包含例如:"vendora::ProductA""vendorb::ProductA""vendora::Productb"我需要删除所有内容(包括)这两个::以便我最终得到:"vendora""vendorb""vendora"我尝试了str.trim(似乎不存在)和str.split,但没有成功。完成此任务的最简单方法是什么? 最佳答案 您可以像正常使用split一样使用pandas.Series.str.split。只需拆分字符串'::',并索引从split方法创建的列表:>>>df=pd.DataFrame(