pandas :得到“ TypeError:只能将整数标量数组转换为标量索引”。尝试合并数据框时 [英] Pandas: Getting "TypeError: only integer scalar arrays can be converted to a scalar index" while trying to merge data frames

查看:106
本文介绍了 pandas :得到“ TypeError:只能将整数标量数组转换为标量索引”。尝试合并数据框时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

重命名 DataFrame 的列后,合并新列时出现错误:

After renaming a DataFrame's column(s), I get an error when merging on the new column(s):

import pandas as pd

df1 = pd.DataFrame({'a': [1, 2]})
df2 = pd.DataFrame({'b': [3, 1]})

df1.columns = [['b']]

df1.merge(df2, on='b')




TypeError:仅整数标量数组可以转换为标量索引

TypeError: only integer scalar arrays can be converted to a scalar index


推荐答案

替换了代码 tmp.columns = [['POR','POR_PORT']] tmp.rename(columns = {'Locode':'POR','Port Name':'POR_PORT'} ,inplace = True)并成功。

Replaced the code tmp.columns = [['POR','POR_PORT']] with tmp.rename(columns={'Locode':'POR', 'Port Name':'POR_PORT'}, inplace=True) and it worked.

这篇关于 pandas :得到“ TypeError:只能将整数标量数组转换为标量索引”。尝试合并数据框时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆