【发布时间】:2013-09-01 06:40:36
【问题描述】:
我是一名 R 用户,我发现自己在迁移到 Python 时遇到了一些困难,尤其是在 Pandas 的索引功能方面。
Household_id 是我的第二列。我根据此列对数据框进行了排序并运行以下指令,返回各种结果(我希望是相同的)。这些表达方式一样吗?如果是这样,为什么我会看到不同的结果?
In [63]: ground_truth.columns
Out[63]: Index([Timestamp, household_id, ... (continues)
In [59]: ground_truth.ix[1107177,'household_id']
Out[59]: 2
In [60]: ground_truth.ix[1107177,1]
Out[60]: 2.0
In [61]: ground_truth.iloc[1107177,1]
Out[61]: 4.0
In [62]: ground_truth['household_id'][1107177]
Out[62]: 2
PS:很遗憾,我无法发布数据(太大)。
【问题讨论】:
-
我可以理解除了浮点数而不是整数之外的所有内容。您使用的是哪个版本的
pandas?我知道曾经有一个涉及向上转换的错误(请参阅here),但很久以前就已修复。也许还有一个? -
我使用的是 Pandas 0.11.0。我期待有整数,因为我做了以下事情: int_vect = np.vectorize(int); ground_truth['household_id'] = int_vect(ground_truth['household_id'])
标签: python indexing pandas slice