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. nginx负载均衡, 配置地址带端口

    nginx.conf  配置如下: upstream wlcf.dev.api { server 127.0.0.1:8833; server 127.0.0.2:8833; } server { l ...

  2. 算法Sedgewick第四版-第1章基础-015一stack只保留last指针

    /************************************************************************* * * A generic queue, impl ...

  3. bzoj2751 容易题

    传送门 题目 为了使得大家高兴,小Q特意出个自认为的简单题(easy)来满足大家,这道简单题是描述如下: 有一个数列A已知对于所有的A[i]都是1~n的自然数,并且知道对于一些A[i]不能取哪些值,我 ...

  4. Luogu 4197 Peaks

    BZOJ 3545 带权限. 考虑离线,把所有边按照从小到大的顺序排序,把所有询问也按照从小到大的顺序排序,然后维护一个并查集和一个权值线段树,每处理一个询问就把比这个询问的$x$更小的边连上,具体来 ...

  5. 同一个id出现多条数据的问题

    这是disial出现的一个bug,花了近两天时间才解决,原因,要在dto的类前加上注解,让它延迟加载. -----后期补充.结合代码.

  6. VS报错之混合模式程序集是针对“v1.1.4322”版的运行时生成的,在没有配置其他信息的情况下,无法在 4.0 运行时中加载该程序集。

    看到一个kinect大牛编写的一个水果忍者的体感游戏版本,让我为自己一直以来只用现有的网页游戏来模拟kinect体感游戏控制感到惭愧,没办法,我还是菜鸟.学习一段后自己模仿星际大战这个游戏,自己写了一 ...

  7. SQLServer存储引擎——02.内存

    SQLServer存储引擎之内存篇: (1)SQL SERVER 内存结构        SQL SERVER 内存结构简图 SQL SERVER 内存空间主要可分为两部分: (1.1)可执行代码(E ...

  8. git CVE-2014-9390 验证以及源码对比

    一 验证部分 首先在ubuntu下面建立如下工程 mkdir repo cd repo git init mkdir -p .GiT/hooks cp post-checkout .GiT/hooks ...

  9. epoll简介

    1.epoll简介 epoll是I/O事件通知工具,与select/poll相比,epoll最大的好处在于它不会随着监听fd数目的增长而效率降低.epoll API既可以用作edge触发的接口,也可以 ...

  10. UC浏览器体验

    1.用户界面: 有两个页面,一个展示网页应用-可添加自己喜欢的网页应用,另一个用来搜索,有推荐的常用的网址,有UC头条,页面下有设置,整体布局常规 2.短期刺激: 没有特别花哨的地方:个人感觉比较实用 ...