基本上,我想这样做
pd.merge(Investments1,Investments2, how = "outer", left_on = left_key, right_on = right_key)
错误是
ValueError: You are trying to merge on object and float64 columns. If you wish to proceed you should use pd.concat
所以我检查 right_on 的类型:
Investments2['SECURITY CODE']
Name: SECURITY CODE, dtype: float64.
但是 left_on 发生的情况是:
Investments2['security code']
Out[104]:
116 11111
118 222222
119 333333
Name: security code, dtype: object
type(Investments2.iloc[1,1])
Out[106]: float
是否存在这样的情况:一列 float 实际上是一个对象,而对象表示一个字符串?
最佳答案
合并之前转换Investments2
。就像,
Investments2['security code'] = Investments2['security code'].transform(float)
或如评论中指出的那样,使用 DataFrame.astype
Investments2['security code'] = Investments2['security code'].astype(float)
关于python - Pandas 的一列 float 结果是对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51256565/