我有以下数据集:
df = pd.DataFrame([
{'Phone': 'Fax(925) 482-1195', 'Fax': None},
{'Phone': 'Fax(406) 226-0317', 'Fax': None},
{'Phone': 'Fax+1 650-383-6305', 'Fax': None},
{'Phone': 'Phone(334) 585-1171', 'Fax': 'Fax(334) 585-1182'},
{'Phone': None, 'Fax': None},
{'Phone': 'Phone(334) 585-1171', 'Fax': 'Fax(334) 585-1176'}]
)
它应该如下所示:
我try 做的是:对于我看到的每一行"Fax",我想截断它并将该记录转移到"Fax"列.
起初,我试图使用这个过滤器只查询匹配的内容:
df[df['Phone'].str.contains("Fax") == True, "Fax"] = df[df['Phone'].str.contains("Fax") == True]
但它不起作用,并出现错误:"TypeError:unhasable type:‘Series’".
有什么主意吗?