Pandas 合并 TypeError:“NoneType”类型的对象没有 len()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48056977/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pandas merge TypeError: object of type 'NoneType' has no len()
提问by Chia Yi
I'm experimenting with pandas merge left_on and right_on params. According to Documentation 1and Documentation 2
我正在试验Pandas合并 left_on 和 right_on 参数。根据文档 1和文档 2
Documentation 1: states that left_on and right_on are field names to join on in left/right DataFrame. Documentation 2: Columns from the left DataFrame to use as keys
文档 1:指出 left_on 和 right_on 是要加入左/右 DataFrame 的字段名称。文档 2:左侧 DataFrame 中的列用作键
What does keysmeans?
钥匙是什么意思?
Following documentation 1:
以下文档1:
left_frame = pd.DataFrame({'key': range(5),
'left_value': ['a', 'b', 'c', 'd', 'e']})
right_frame = pd.DataFrame({'key': range(2,7),
'right_value': ['f', 'g', 'h', 'i', 'j']})
I did this:
我这样做了:
df = pd.merge(left_frame,right_frame,how='right',right_on='key')
left_frame has 'key' as field name, but yet it returns
left_frame 将“key”作为字段名称,但它返回
TypeError: object of type 'NoneType' has no len()
回答by jezrael
It seems you need:
看来你需要:
df = pd.merge(left_frame, right_frame, how='right', on='key')
because same left and right column names.
因为左右列名称相同。
If columns names are different:
如果列名称不同:
df = pd.merge(left_frame, right_frame, how='right', right_on='key1', left_on='key2')
What does keysmeans?
钥匙是什么意思?
If check merge
:
如果检查merge
:
on: label or list
Field names to join on. Must be found in both DataFrames. If on is None and not merging on indexes, then it merges on the intersection of the columns by default.
on: 标签或列表
要加入的字段名称。必须在两个 DataFrame 中都能找到。如果 on 为 None 并且不合并索引,则默认情况下在列的交集上合并。
And it means values in columns to join on.
这意味着要加入的列中的值。