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

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:

主站蜘蛛池模板: 贵德县| 内黄县| 蚌埠市| 大关县| 永年县| 射阳县| 黑龙江省| 闽清县| 东台市| 孝义市| 河东区| 阿合奇县| 金塔县| 洛浦县| 崇州市| 京山县| 龙岩市| 连云港市| 中超| 江门市| 皮山县| 西丰县| 定结县| 朝阳区| 古田县| 察隅县| 泰州市| 岱山县| 安陆市| 岑溪市| 贺兰县| 宝山区| 巩义市| 岑巩县| 右玉县| 金溪县| 平武县| 维西| 嘉兴市| 林西县| 天长市|