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

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:

主站蜘蛛池模板: 长兴县| 泽州县| 镇坪县| 拉萨市| 白城市| 垫江县| 永德县| 凯里市| 独山县| 乡城县| 修文县| 独山县| 石渠县| 云安县| 洛隆县| 罗平县| 富顺县| 读书| 改则县| 眉山市| 华安县| 鸡东县| 西吉县| 昭通市| 莱阳市| 灵寿县| 定西市| 浠水县| 宁武县| 年辖:市辖区| 锦屏县| 顺昌县| 克什克腾旗| 山东| 鄱阳县| 西宁市| 海盐县| 阳山县| 乳源| 邹城市| 安化县|