Python问题解决:TypeError: ‘<‘ not supported between instances of ‘float‘ and ‘str‘

出错代码:

#按区域得到每组的数据

key = df[['区域','产品类别']].apply(tuple,axis=1)
gp = df.groupby(key)

for key,g in gp:
    print(f'{key}:{type(g)}')

报错:

TypeError: '<' not supported between instances of 'float' and 'str'

解决方法:

key = df[['区域','产品类别']].apply(tuple,axis=1).astype(str)
gp = df.groupby(key)

for key,g in gp:
    print(f'{key}:{type(g)}')

Python问题解决:TypeError: ‘<‘ not supported between instances of ‘float‘ and ‘str‘_第1张图片 

 

你可能感兴趣的:(Python,python)