我有一个数据框,其中每个列中的一列包含json字符串,例如{'1':105,'2':105,'3':110}。
当我尝试执行df.drop_duplicates(subset = ['prices'],keep ='last')删除重复项时
它返回一个错误。我没有问题将其他列放在数据框中作为子集来删除重复项。但是我不能以这种格式使用此列。有想法吗?
答案 0 :(得分:0)
您正在尝试在字典类型上使用Chunk
,这就是为什么它会导致class Main():
def __init__(self):
self.prog = 1
self.ctx = 2
class Chunk():
def __init__(self, pos_in_world_x, pos_in_world_y):
#self.chunksize = settings.blocks_per_chunk
self.prog = m.prog
self.ctx = m.ctx
m = Main()
c = Chunk(3, 4)
print(c.prog) # 1
print(c.ctx) # 2
错误的原因。您可以这样做:
.drop_duplicates
这里唯一的技巧是使用unhashable type dict
将字典转换为数据帧。