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. 导出Excel解决方案之一NOPI

    一.概要 导出Excel这个功能相信很多人都做过,但是实现这个功能解决方案有好几种,今天我未大家介绍一种比较新的,其实也不新了- -!它叫NPOI,可以完美操作EXCEl的导入和导出操作,让我们一起看 ...

  2. GPG入门

    GPG入门   摘自https://www.jianshu.com/p/1257dbf3ed8e   Nitroethane 关注 2016.07.19 17:36* 字数 1003 阅读 6560评 ...

  3. Ubuntu中安装LAMP

    现在,很多人可能已经用上ubuntu了,大家可能花了大量时间在ubuntu的美化上,这无可厚非,但是,ubuntu应该给我们的工作和学习带来更多的便利和方便.ubuntu作为linux,为我们提供了强 ...

  4. json序列化.xml序列化.图片转base64.base64转图片.生成缩略图.IEnumerable<TResult> Select<TSource, TResult>做数据转换的五种方式

     JSON序列化 /// <summary> /// JSON序列化 /// </summary> public static class SPDBJsonConvert { ...

  5. 【C#】EF学习<一> CodeFist

    [第一篇]ASP.NET MVC快速入门之数据库操作(MVC5+EF6) 目录 [第一篇]ASP.NET MVC快速入门之数据库操作(MVC5+EF6) http://www.cnblogs.com/ ...

  6. How can I list colors in WPF with XAML?

    How can I get list of all colors I can pick in Visual Studio Designer (which is System.Windows.Media ...

  7. 用递归算法返回该元素id下面的所有子集id

    private List<int> listAreaId = new List<int>(); /// <summary> /// 递归获取本区域下面的所有子集 / ...

  8. 20164305 徐广皓 Exp6 信息搜集与漏洞扫描

    信息搜集技术与隐私保护 间接收集 无物理连接,不访问目标,使用第三方信息源 使用whois/DNS获取ip 使用msf中的辅助模块进行信息收集,具体指令可以在auxiliary/gather中进行查询 ...

  9. Git 分支管理-git stash 和git stash pop

    https://blog.csdn.net/u010697394/article/details/56484492 合并分支,冲突是难免的,在实际协作开发中我们遇到的情况错综复杂,今天就讲两个比较重要 ...

  10. java读取 500M 以上文件,java读取大文件

    java 读取txt,java读取大文件 设置缓存大小BUFFER_SIZE ,Config.tempdatafile是文件地址 来源博客http://yijianfengvip.blog.163.c ...