pandas 为什么 FrozenList 与元组不同?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25676107/
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
Why is FrozenList different from tuple?
提问by dmvianna
from pandas.core.base import FrozenList
Type: type
String form: <class 'pandas.core.base.FrozenList'>
File: /site-packages/pandas/core/base.py
Docstring:
Container that doesn't allow setting item *but*
because it's technically non-hashable, will be used
for lookups, appropriately, etc.
Why not just use tuple? What extra functionality would a FrozenList offer?
为什么不直接使用tuple?FrozenList 会提供哪些额外的功能?
回答by Jeff
This is an internal pandas construct. Not using tuple because:
这是一个内部的Pandas结构。不使用元组,因为:
- It inherits from a common pandas class
- Its customizable (e.g. the repr)
- It doesn't have quite all of the functions of a tuple (some are disabled)
- It nots hashable (so more like a list here and not a tuple)
- 它继承自一个普通的 Pandas 类
- 它的可定制(例如repr)
- 它没有元组的所有功能(有些被禁用)
- 它不是可散列的(所以更像是这里的列表而不是元组)
The construct is used to represent a MultiIndex levels,labels, and names. The point of it is to prevent modification of these thru attributes and force the use of methods (e.g. set_levels()). As the state of these cannot be changed independent (for level/labels), but must be changed together.
该构造用于表示 MultiIndex 级别、标签和名称。它的重点是防止修改这些直通属性并强制使用方法(例如set_levels())。由于这些状态不能单独更改(对于级别/标签),但必须一起更改。
These are 'public' properties though, so it needed an access mechanism that could do all of this (and yet still be changed internally if necessary, for performance reasons).
不过,这些是“公共”属性,因此它需要一种可以完成所有这些操作的访问机制(但出于性能原因,必要时仍可在内部进行更改)。

