在pandas中,您可以通过
获取数据框中列的唯一值#List unique values in the df['name'] column
df.name.unique()
Python如何将函数名称转换为字符串参数' name'?
答案 0 :(得分:2)
数据框覆盖__getattr__
以挂钩属性解析。这允许从df.anything
返回任意对象。该实例在self._internal_names_set
中维护一个“真实”属性名称的内部列表,并在self._info_axis
中维护一个列名列表。
def __getattr__(self, name):
"""After regular attribute access, try looking up the name
This allows simpler access to columns for interactive use.
"""
# Note: obj.x will always call obj.__getattribute__('x') prior to
# calling obj.__getattr__('x').
if (name in self._internal_names_set or name in self._metadata or
name in self._accessors):
return object.__getattribute__(self, name)
else:
if name in self._info_axis:
return self[name]
return object.__getattribute__(self, name)
来源是here。