我有一个这样的数据框:
d = {'col1': ["url/a/b/c/d", "url/b/c/d", "url/j/k", "url/t/y", 'url/r/a/y'],
'id': [1, 2, 3, 4, 5]}
df = pd.DataFrame(data=d)
我想在原始数据帧的基础上创建另一个数据帧,其中我有only the part of the strings that repeat.个
我的 idea 是对每个/
进行拆分,然后将数据帧的第一行与数据帧的其余行(因此对所有行都是一行)进行比较,以判断是否相等.因此,我在这个问题上的初始示例的结果将是:
result = {'col1': [["a", "b", "c", "d"], ["b", "c", "d"], [""], ["y"], ["a", "y"]],
'id': [1, 2, 3, 4, 5]}
df_result = pd.DataFrame(data=result)
此外,我不可能没有错误地构建这个函数……有什么主意吗?
谢谢!