pandas有两个最主要的数据结构,分别是Series
和DataFrame
,所以一开始的任务就是好好熟悉一下这两个数据结构。
一.Series
官方文档: pandas.Series
Series是类似于一维数组的对象,由一组数据(各种numpy的数据类型)以及一组与之相关的标签组成。首先看一下怎么构造出Series来。
class pandas.Series(data=None, index=None, dtype=None, name=None, copy=False, fastpath=False)
参数:
data : 类array的,字典,或者是标量
index : 索引列表,和data的长度一样
dtype : numpy.dtype,没有的话,会根据data内容自动推断
copy : boolean,默认是False
常用属性:
接下来给出属性,常用的属性经常用到的不多,其他的属性可以查上面给出的文档。
属性:
dtype 数据元素的类型.
empty 是否为空.
index 索引对象
ix A primarily label-location based indexer, with integer position fallback.
loc Purely label-location based indexer for selection by label.
name
nbytes return the number of bytes in the underlying data
ndim 返回数据部分的维度大小
shape 返回一个元组,表示数据的形状
size 返回元素的数量。
strides return the strides of the underlying data
values 返回Series对象中的值部分,ndarray类型
这里直接给出例子来创建Series。有很多中创建方式,很繁杂,所以就把例子放在一起,就一目了然了。
# -*- coding: utf-8 -*-