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

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

说明你的 np 矩阵 data["from"] 里面不仅有 float 类型,还有 str 类型,需要统一成同一类型。
例如统一为 float,则代码改为:
f = data["from"].astype(float)
for i in sorted(f.unique()):
print(i, data[f == i].shape[0])