pandas.Series

class pandas.Series(data=Noneindex=Nonedtype=Nonename=Nonecopy=Falsefastpath=False)

One-dimensional ndarray with axis labels (including time series).

Labels need not be unique but must be any hashable type. The object supports both integer- and label-based indexing and provides a host of methods for performing operations involving the index. Statistical methods from ndarray have been overridden to automatically exclude missing data (currently represented as NaN)

Operations between Series (+, -, /, , *) align values based on their associated index values– they need not be the same length. The result index will be the sorted union of the two indexes.

Parameters :

data : array-like, dict, or scalar value

Contains data stored in Series

index : array-like or Index (1d)

Values must be unique and hashable, same length as data. Index object (or other iterable of same length as data) Will default to np.arange(len(data)) if not provided. If both a dict and index sequence are used, the index will override the keys found in the dict.

dtype : numpy.dtype or None

If None, dtype will be inferred

copy : boolean, default False

Copy input data

Series 类似数组,但是它有标签(label) 或者索引(index).

1. 从最简单的series开始看。

from pandas import Series, DataFrame
import pandas as pd
ser1 = Series([1,2,3,4])
print(ser1)
#0 1
#1 2
#2 3
#3 4
#dtype: int64

此时因为没有设置index,所以用默认

2. 加上索引

ser2 = Series(range(4),index=['a','b','c','d'])
print(ser2)
#a 0
#b 1
#c 2
#d 3
#dtype: int64

3. dictionnary 作为输入

dict1 = {'ohio':35000,'Texas':71000,'Oregon':1600,'Utah':500}
ser3 = Series(dict1)
#Oregon 1600
#Texas 71000
#Utah 500
#ohio 35000
#dtype: int64

key:默认设置为index

dict1 = {'ohio':35000,'Texas':71000,'Oregon':1600,'Utah':500}
ser3 = Series(dict1)
#Oregon 1600
#Texas 71000
#Utah 500
#ohio 35000
#dtype: int64
print(ser3)
states = ['California', 'Ohio', 'Oregon', 'Texas']
ser4 = Series(dict1,index = states)
print(ser4)
#California NaN
#Ohio NaN
#Oregon 1600.0
#Texas 71000.0
#dtype: float64

用了dictionary时候,也是可以特定的制定index的,当没有map到value的时候,给NaN.

print(pd.isnull(ser4))
#California True
#Ohio True
#Oregon False
#Texas False
#dtype: bool

函数isnull判断是否为null

print(pd.isnull(ser4))
#California True
#Ohio True
#Oregon False
#Texas False
#dtype: bool

函数notnull判断是否为非null

print(pd.notnull(ser4))
#California False
#Ohio False
#Oregon True
#Texas True
#dtype: bool

4. 访问元素和索引用法

print (ser2['a']) #
#print (ser2['a','c']) error
print (ser2[['a','c']])
#a 0
#c 2
#dtype: int64
print(ser2.values) #[0 1 2 3]
print(ser2.index) #Index(['a', 'b', 'c', 'd'], dtype='object')

5. 运算, pandas的series保留Numpy的数组操作

print(ser2[ser2>2])
#d 3
#dtype: int64
print(ser2*2)
#a 0
#b 2
#c 4
#d 6
#dtype: int64
print(np.exp(ser2))
#a 1.000000
#b 2.718282
#c 7.389056
#d 20.085537
#dtype: float64

6. series 的自动匹配,这个有点类似sql中的full join,会基于索引键链接,没有的设置为null

print (ser3+ser4)
#California NaN
#Ohio NaN
#Oregon 3200.0
#Texas 142000.0
#Utah NaN
#ohio NaN
#dtype: float64

7. series对象和索引都有一个name属性

ser4.index.name = 'state'
ser4.name = 'population count'
print(ser4)
#state
#California NaN
#Ohio NaN
#Oregon 1600.0
#Texas 71000.0
#Name: population count, dtype: float64

8.预览数据

print(ser4.head(2))
print(ser4.tail(2))
#state
#California NaN
#Ohio NaN
#Name: population count, dtype: float64
#state
#Oregon 1600.0
#Texas 71000.0
#Name: population count, dtype: float64

Python Pandas -- Series的更多相关文章

  1. python. pandas(series,dataframe,index) method test

    python. pandas(series,dataframe,index,reindex,csv file read and write) method test import pandas as ...

  2. python pandas.Series&&DataFrame&& set_index&reset_index

    参考CookBook :http://pandas.pydata.org/pandas-docs/stable/cookbook.html Pandas set_index&reset_ind ...

  3. python pandas ---Series,DataFrame 创建方法,操作运算操作(赋值,sort,get,del,pop,insert,+,-,*,/)

    pandas 是基于 Numpy 构建的含有更高级数据结构和工具的数据分析包 pandas 也是围绕着 Series 和 DataFrame 两个核心数据结构展开的, 导入如下: from panda ...

  4. Python pandas 0.19.1 Intro to Data Structures 数据结构介绍 文档翻译

    官方文档链接http://pandas.pydata.org/pandas-docs/stable/dsintro.html 数据结构介绍 我们将以一个快速的.非全面的pandas的基础数据结构概述来 ...

  5. Python pandas学习总结

    本来打算学习pandas模块,并写一个博客记录一下自己的学习,但是不知道怎么了,最近好像有点急功近利,就想把别人的东西复制过来,当心沉下来,自己自觉地将原本写满的pandas学习笔记删除了,这次打算写 ...

  6. pandas.Series

    1.系列(Series)是能够保存任何类型的数据(整数,字符串,浮点数,Python对象等)的一维标记数组.轴标签统称为索引. Pandas系列可以使用以下构造函数创建 - pandas.Series ...

  7. Python pandas快速入门

    Python pandas快速入门2017年03月14日 17:17:52 青盏 阅读数:14292 标签: python numpy 数据分析 更多 个人分类: machine learning 来 ...

  8. Python pandas & numpy 笔记

    记性不好,多记录些常用的东西,真·持续更新中::先列出一些常用的网址: 参考了的 莫烦python pandas DOC numpy DOC matplotlib 常用 习惯上我们如此导入: impo ...

  9. 【跟着stackoverflow学Pandas】 - Adding new column to existing DataFrame in Python pandas - Pandas 添加列

    最近做一个系列博客,跟着stackoverflow学Pandas. 以 pandas作为关键词,在stackoverflow中进行搜索,随后安照 votes 数目进行排序: https://stack ...

随机推荐

  1. Blender 基础 骨架-02 骨架的各种呈现方式

    Blender 基础 骨架-02 - 骨架的各种呈现方式 我使用的Blender版本:Blender V 2.77 前言 在 Blender 基础 骨架-01 教程里面,将骨架和模型联系在一起,我们在 ...

  2. 旋转矩阵(Rotate Matrix)的性质分析

    博客转载自:http://www.cnblogs.com/caster99/p/4703033.html 学过矩阵理论或者线性代数的肯定知道正交矩阵(orthogonal matrix)是一个非常好的 ...

  3. acrord32 pdf自动化

    这个东西就是帮助用户自动化处理pdf的 . 可以看作是adobe reader的命令行

  4. Posters TopCoder - 1684

    传送门 分析 首先我们不难想到1e4^5的暴力枚举,但显然这是不行的,于是我们考虑对于每一张海报肯定有一种最优情况使得它至少有一条边要么靠着板子的边要么靠着之前的某一张海报的边,这样我们便可以将复杂度 ...

  5. Entity Framework Tutorial Basics(25):Delete Single Entity

    Delete Entity using DBContext in Disconnected Scenario: We used the Entry() method of DbContext to m ...

  6. jQuery 插件开发——PopupLayer(弹出层)

    导读:上次写了一篇关于GridView的插件开发方法,上几天由于工作需要,花了一天左右的事件封装了popupLayer(弹出层)插件.今天有时间就记录一下自己的开发思想与大家分享下,同时也算是对这段时 ...

  7. Django之博客系统邮件分享博客

    在上一章中,我们创建了一个基础的博客应用,我们能在http://127.0.0.1:8000/blog/显示我们的博客.在这一章我们将尝试给博客系统添加一些高级的特性,比如通过email来分享帖子,添 ...

  8. ajaxs

    AJAX 是一种独立于 Web 服务器软件的浏览器技术.AJAX 基于下列 Web 标准:JavaScript XML HTML CSS 在 AJAX 中使用的 Web 标准已被良好定义,并被所有的主 ...

  9. 魔法少女 LJJ——线段树

    题目 [题目描述] 在森林中见过会动的树,在沙漠中见过会动的仙人掌过后,魔法少女 LJJ 已经觉得自己见过世界上的所有稀奇古怪的事情了. LJJ 感叹道“这里真是个迷人的绿色世界,空气清新.淡雅,到处 ...

  10. P4196 [CQOI2006]凸多边形 半平面交

    \(\color{#0066ff}{题目描述}\) 逆时针给出n个凸多边形的顶点坐标,求它们交的面积.例如n=2时,两个凸多边形如下图: 则相交部分的面积为5.233. \(\color{#0066f ...