Python Pandas pd.merge_asof:TypeError:'NoneType'对象不可调用 [英] Python Pandas pd.merge_asof: TypeError: 'NoneType' object is not callable
本文介绍了Python Pandas pd.merge_asof:TypeError:'NoneType'对象不可调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚发现了pandas merge_asof函数,并试图使其工作.下面是一些示例代码,可重现我看到的错误:
I just discovered pandas merge_asof function and trying to get it to work. Below is some sample code that reproduces the error I am seeing:
d1 = pd.DataFrame.from_dict({'id':[646327.0, 645714.0, 645462.0],
'units1':[1.7723982570833334, 1.7723982570833334, 5.772398257083333]})
d2 = pd.DataFrame.from_dict({'id':[645462.0, 645714.0, 646327.0, 645462.0, 645714.0,
645462.0,
645714.0,
645462.0,
645714.0,
645462.0], 'units2':[0.7723988920833333, 0.7723988920833333, 0.7723988920833333, 3.7723988920833333,
3.7723988920833333,
4.772398892083333,
4.772398892083333,
5.772398892083333,
5.772398892083333,
6.772398892083333]})
当我尝试使用pd.merge_asof时:
And when I try to use pd.merge_asof:
d3 = pd.merge_asof(d1, d2, by = 'id', left_on = 'units1', right_on = 'units2',
direction='nearest')
我收到一个错误,一个Nonetype错误.有人知道这是怎么回事吗?我的语法不正确吗?
I get an error a Nonetype error.Anyone know what's going on here? Is my syntax incorrect?
推荐答案
我能够通过将id
强制转换为int
来解决此问题.
I was able to solve this problem by casting id
to an int
.
d1['id'] = d1['id'].astype('int')
d2['id'] = d2['id'].astype('int')
d3 = pd.merge_asof(d1, d2, by = 'id', on = 'units', direction='nearest')
这篇关于Python Pandas pd.merge_asof:TypeError:'NoneType'对象不可调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文