教育类网站开发文档国外 精美 网站
教育类网站开发文档,国外 精美 网站,小程序模板页,网站接入地如错误消息所示#xff0c;drop_duplicates不能用于数据帧中的列表。但是#xff0c;您可以在作为str的数据帧上删除重复项#xff0c;然后使用结果中的索引从原始df中提取行。设置df pd.DataFrame({Keyword: {0: apply, 1: apply, 2: apply, 3: terms, 4: terms},X: {0: […如错误消息所示drop_duplicates不能用于数据帧中的列表。但是您可以在作为str的数据帧上删除重复项然后使用结果中的索引从原始df中提取行。设置df pd.DataFrame({Keyword: {0: apply, 1: apply, 2: apply, 3: terms, 4: terms},X: {0: [1, 2], 1: [1, 2], 2: xy, 3: xx, 4: yy},Y: {0: yy, 1: yy, 2: yx, 3: ix, 4: xi}})#Drop directly causes the same errordf.drop_duplicates()Traceback (most recent call last):...TypeError: unhashable type: list解决方案#convert hte df to str type, drop duplicates and then select the rows from original df.df.loc[df.astype(str).drop_duplicates().index]Out[205]:Keyword X Y0 apply [1, 2] yy2 apply xy yx3 terms xx ix4 terms yy xi#the list elements are still list in the final results.df.loc[df.astype(str).drop_duplicates().index].loc[0,X]Out[207]: [1, 2]Edit: replaced iloc with loc. In this particular case, both work as theindex matches the positional index, but it is not general
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/85830.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!