英文:
what is ".cat" in ".cat.categories"?
问题
我不确定.cat
是什么,以及为什么我们需要它,而.categories
本身已经在要求解释器列出所选类别了?例如,为什么我要使用这个:
housing_df.REMODEL.cat.categories
而不是这个:
housing_df.REMODEL.categories
Pandas文档解释了"String.cat.categories",但我不理解那个。
英文:
I am not sure what .cat
is and why we need it while .categories
itself is already asking the interpreter to list the category of choice ?
For example, why should I use this:
housing_df.REMODEL.cat.categories
And not this:
housing_df.REMODEL.categories
Pandas documentation explains "String.cat.categories" but I do not understand that.
答案1
得分: 0
.cat
被称为访问器对象。它允许您访问特定于分类列的属性和方法。在pandas中有类似的访问器:.dt
用于日期时间,.str
用于字符串,.plot
用于绘图等等。这是pandas开发人员做出的设计决策。通常,这些用于命名空间,以便更好地组织属性和方法,以避免名称冲突。
英文:
.cat
is called an accessor object. It allows you to access attributes and methods that are specific to categorical columns. There are similar accessors in pandas: .dt
for date-time, .str
for string, .plot
for plotting and so on. This is a design decision made by pandas developers. In general, these are used for namespacing so that attributes and methods are better organized and they don't cause name collision.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论