我有以下格式的数据:
pastLocation | currentLocation
delhi | bangalore
delhi | london,pune,delhi
mumbai | mumbai
pune | pune, noida
我必须创建一个名为changeInLocation
的新列,如果pastLocation
出现在currentLocation
中,那么新列的值将是0
否则1
。
例如,在第二行中,pastLocation
即德里出现在相应的currentLocation
中,因此changeInLocation
的值应该是0
输出格式如下:
pastLocation | currentLocation | changeInLocation
delhi | bangalore | 1
delhi | london,pune,delhi | 0
mumbai | mumbai | 0
pune | pune, noida | 0
耶斯雷尔的类似解决方案(无论如何更完整),但没有铸造:
与jezrael的解决方案类似,但要注意删除空格并使用
set
来提高性能:使用
apply
和in
检查成员身份,然后强制转换为int
:另一个解决方案是压缩列并使用
list comprehension
:相关问题 更多 >
编程相关推荐