官术网_书友最值得收藏!

Lookup by label using the [] operator and the .ix[] property

An implicit label lookup is performed using the [] operator. This operator normally looks up values based upon the given index labels.

Let's start by using the following Series:

A single value can be looked up using just the index label of the desired item:

Multiple items can be retrieved at once using a list of index labels:

We can also look up values using integers that represent positions:

This works purely because the index is not using integer labels. If integers are passed to [], and the index has integer values, then the lookup is performed by matching the values passed in to the values of the integer labels.

This can be demonstrated using the following Series:

The following looks up values at labels 13 and 10, not positions 13 and 10:

Lookup using the [] operator is identical to using the .ix[] property. However, .ix[] has been deprecated since pandas version 0.20.1. The reason for the deprecation is the confusion caused by integers being passed to the operators and the difference in operation depending on the type of the label in the index.

The ramifications of this is that neither [] or .ix[] should be used for lookup. Instead, use the .loc[] and .iloc[] properties, which explicitly look up by label or position only.

主站蜘蛛池模板: 海伦市| 古田县| 长沙县| 化德县| 南丹县| 建湖县| 桃江县| 康乐县| 衡阳市| 隆子县| 贵港市| 武功县| 佛山市| 连云港市| 景德镇市| 呼和浩特市| 扎囊县| 承德市| 永川市| 西盟| 乌兰察布市| 陈巴尔虎旗| 万源市| 西盟| 晋中市| 华亭县| 娄底市| 锡林浩特市| 斗六市| 横山县| 永定县| 区。| 乐陵市| 岢岚县| 崇信县| 兰西县| 蓬莱市| 昌吉市| 蒲江县| 佛坪县| 海淀区|