Python Pandas:什么是 NDFrame 对象(什么是非 NDFrame 对象)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42973200/
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: what is a NDFrame object (and what is a non-NDFrame object)
提问by ntg
I am trying to concat two DataFrames and am getting a 'TypeError: cannot concatenate a non-NDFrame object'
error. I have been looking around, there are a lot of people getting this error, most of the time when they try to do something other than what their code really does, (so the answers solve their particular but unrelated questions)
我正在尝试连接两个 DataFrame 并且出现'TypeError: cannot concatenate a non-NDFrame object'
错误。我一直在环顾四周,有很多人都遇到了这个错误,大多数时候他们试图做一些不同于他们的代码真正做的事情,(所以答案解决了他们特定但不相关的问题)
My question is not to solve my particular problem, but to understand the error... What is a non-NDFrame object? Why can it not be concatenated?
我的问题不是要解决我的特定问题,而是要了解错误...什么是非 NDFrame 对象?为什么不能串联?
Also, why is this about NDFrames (What are those, and where do I use them? Are all DataFrames NDFrames? Are there any NDFrames that are not DataFrames?)...
另外,为什么这是关于 NDFrames(那些是什么,我在哪里使用它们?所有 DataFrames 都是 NDFrames?是否有任何 NDFrames 不是 DataFrames?)...
I would understand if it said 'TypeError: cannot concatenate a non-DataFrame object'
(though I am not sure if them not being DataFrames was the cause of my error) This is mainly my curiosity questing, I am not trying to hunt any specific bug...
我会理解它是否说'TypeError: cannot concatenate a non-DataFrame object'
(虽然我不确定它们是否不是 DataFrames 是我错误的原因)这主要是我的好奇心,我不想寻找任何特定的错误......
回答by John Zwinck
N-dimensional analogue of DataFrame. Store multi-dimensional in a size-mutable, labeled data structure
DataFrame 的 N 维模拟。将多维存储在大小可变的标记数据结构中
class DataFrame(NDFrame): Two-dimensional size-mutable, potentially heterogeneous tabular data structure with labeled axes (rows and columns). Arithmetic operations align on both row and column labels. Can be thought of as a dict-like container for Series objects.
class DataFrame(NDFrame):二维大小可变,具有标记轴(行和列)的潜在异构表格数据结构。算术运算在行和列标签上对齐。可以将其视为系列对象的类 dict 容器。
As you can see, a DataFrame is a subclass (i.e. special case) of NDFrame. In Pandas programs generally, DataFrame is used a lot and NDFrame is used rarely. In fact, Pandas has Series for 1D, DataFrame for 2D, and for most people that's the end, even though half of Pandas' name is for Panel
which Pandas also has, but most people do not use.
如您所见,DataFrame 是 NDFrame 的子类(即特殊情况)。在 Pandas 程序中,一般使用 DataFrame 较多,很少使用 NDFrame。事实上,熊猫系列具有一维,数据帧的2D,对于大多数人这就是结束,即使大熊猫名字的一半用于Panel
其熊猫也有,但大多数人不使用。
There is/was even a 4D thing in Pandas, but truly no one uses it (this being the internet, someone will now appear to say they do!). For higher dimensions than two or maybe three, some people have shifted their efforts to xarray. That's probably where it's at if your ambitions cannot be contained in 2D.
Pandas 中甚至有/曾经有一个 4D 东西,但确实没有人使用它(这就是互联网,现在似乎有人会说他们这样做了!)。对于比两个或三个更高的维度,有些人已将他们的努力转移到xarray。如果您的野心不能包含在 2D 中,那可能就是它所在的位置。