与Python Pandas中的因子变量最接近的等效项 [英] Closest equivalent of a factor variable in Python Pandas

查看:89
本文介绍了与Python Pandas中的因子变量最接近的等效项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

R因子变量最接近的等效项是什么://pandas.pydata.org/> Python熊猫?

What is the closest equivalent to an R Factor variable in Python pandas?

推荐答案

这个问题似乎是一年前的事了,但是由于它仍然开放,所以这里有一个更新. pandas引入了categorical dtype,其操作与R中的factors非常相似.有关更多信息,请参见此链接:

This question seems to be from a year back but since it is still open here's an update. pandas has introduced a categorical dtype and it operates very similar to factors in R. Please see this link for more information:

http://pandas-docs.github.io/pandas- docs-travis/categorical.html

从上面的链接中复制一个片段,显示如何在熊猫中创建"factor"变量.

Reproducing a snippet from the link above showing how to create a "factor" variable in pandas.

In [1]: s = Series(["a","b","c","a"], dtype="category")

In [2]: s
Out[2]: 
0    a
1    b
2    c
3    a
dtype: category
Categories (3, object): [a < b < c]

这篇关于与Python Pandas中的因子变量最接近的等效项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆