【发布时间】:2021-03-07 02:31:01
【问题描述】:
customer_name ANDY
number_of_product_variants 2
number_of_channels 1
number_of_discount_codes 1
order_count 1
order_name #1100,#1100
discount_code Christmas2020, Christmas2020
channel Instagram, Instagram
product_variant Avengers Set A, Avengers Set B
仅当字符串包含重复项时,我才想删除重复的单词。
预期输出:
customer_name ANDY
number_of_product_variants 2
number_of_channels 1
number_of_discount_codes 1
order_count 1
order_name #1100
discount_code Christmas2020
channel Instagram
product_variant Avengers Set A, Avengers Set B
我试过的代码:
def unique_string(l):
ulist = []
[ulist.append(x) for x in l if x not in ulist]
return ulist
customer_df['channel_2']=customer_df['channel']
customer_df['channel_2'].apply(unique_string)
将下面的代码仅用于channel 列会返回:
0 [S, e, a, r, c, h, ,]
1 [P, a, i, d, , A, s, :, S, o, c, l]
2 [P, a, i, d, , A, s, :, S, o, c, l, ,]
3 [U, n, k, o, w, ,]
```
【问题讨论】:
标签: python python-3.x pandas list