python pandas 库学习使用笔记
Series数据类型
Series is a one-dimensional labeled array capable of holding any data type (integers, strings, floating point numbers, Python objects, etc.). The axis labels are collectively referred to as the index如同一个一维的数据容器,支持诸多的其他数据。
语法:
s = pd.Series(data, index=index)(pd为pandas的别名)
The passed index is a list of axis labels. Thus, this separates into a few cases depending on what data is(index为一个列表)
Here, data can be many different things:
a Python dict
an ndarray
a scalar value (like 5)
创建Series的例子
1.From ndarray(由numpy中的ndarray数组对象创建)
If data is an ndarray, index must be the same length as data. If no index is passed, one will be created having values [0, …, len(data) - 1].
index 可以用户自定义,用户没有定义则自动给出(从零开始)。两种方式的index长度与数据长度一致。2.From dict
没有对应的index值,将以NaN补充
From scalar value
If data is a scalar value, an index must be provided. The value will be repeated to match the length of index.(需指明index)
Series相当一个数据容器,data可以是多种数据类型,不止列出的这些,index列表中的元素与具体的数据值对应。
参考pandas官网