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

Creating a Series using Python lists and dictionaries

A Series can be created from a Python list:

The first column of numbers represents the label in the index of the Series. The second column contains the values. dtype: int64 denotes that the data type of the values in the Series is int64.

By default, pandas will create an index consisting of consecutive integers starting at 0. This makes the series look like an array in many other programming languages. As an example, we can look up the value at label 3:

This lookup was by label value, not 0-based position. We will examine this in detail later in the chapter.

Data types other than integers can be used. The following creates a series of string values:

To create a series consisting of a sequence of n identical values v, use the Python shorthand for list creation, [v]*n. The following creates five values of 2:

A similar type of shorthand is the following, which uses the Python shorthand to use each character as a list item:

A Series can be directly initialized from a Python dictionary. When using a dictionary, the keys of the dictionary are used as the index labels:

主站蜘蛛池模板: 库尔勒市| 德钦县| 万荣县| 黄梅县| 兴业县| 伊金霍洛旗| 涟源市| 安陆市| 白河县| 武乡县| 鄱阳县| 彭阳县| 怀集县| 缙云县| 阿坝县| 凤庆县| 鹿泉市| 囊谦县| 高雄县| 金沙县| 体育| 安新县| 常熟市| 漠河县| 和硕县| 连城县| 新巴尔虎左旗| 邹城市| 南木林县| 五台县| 怀集县| 梅州市| 华亭县| 阳东县| 湘乡市| 达孜县| 沅陵县| 富民县| 博湖县| 尼玛县| 通山县|