python - Pandas 的一列 float 结果是对象?

标签 python object merge

基本上,我想这样做

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/

相关文章:

python - 在 Python 中提取一些 HTML 标记值

java - 如何向 JTextPane 添加方法

c# - 如何更新扩展方法中的字典元素?

python - Python 中的内置类元类

python请求库传递逗号分隔的id作为参数

javascript - 添加/覆盖数组中的对象

git - merge : Hg/Git vs. SVN

r - 在 R 中合并两个具有常见和不常见样本的数据框

python - 检查Databricks中是否存在该路径

java - SQL 到对象,多对多带字段