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

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:

主站蜘蛛池模板: 嵊泗县| 海盐县| 文山县| 犍为县| 南城县| 根河市| 贺兰县| 江北区| 桃源县| 新野县| 蛟河市| 视频| 安多县| 双牌县| 阿拉善左旗| 开远市| 出国| 呼伦贝尔市| 娱乐| 镇赉县| 沾化县| 沙湾县| 博客| 保靖县| 库尔勒市| 宁陵县| 阳山县| 泗水县| 内江市| 石嘴山市| 新平| 库尔勒市| 舟曲县| 贺兰县| 南木林县| 石屏县| 连平县| 克山县| 綦江县| 普宁市| 兴化市|