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. eclips git中的add to Index无效解决

    今天在使用eclips git中的add to Index,发现其无效,具体如下 问题描述: 通过export导入一个git java项目 在java工程中新增一个类文件IndicatorCalcTe ...

  2. Luogu 3530 [POI2012]FES-Festival

    我是真的不会写差分约束啊呜呜呜…… BZOJ 2788被权限了. 首先对于第一个限制$x + 1 = y$,可以转化成$x + 1 \leq y \leq x + 1$, 所以连一条$(y, x, - ...

  3. linux文件夹删除、创建

    一.删除文件夹 rm -rf ./html2imag 二.创建文件夹 mkdir html2image

  4. 简单VBS教程.RP

    Mimick同菜鸟==.文转豆瓣~:https://www.douban.com/note/88562379/ 讲一下VBScript.主要面向菜鸟,懂得编程的朋友就不要浪费时间了,如果你想接触以下V ...

  5. php 函数追踪扩展 phptrace

    php 函数追踪扩展 phptrace 介绍 phptrace 是一个低开销的用于跟踪.分析 php 运行情况的工具. 它可以跟踪 php 在运行时的函数调用.请求信息.执行流程.并且提供有过滤器.统 ...

  6. [译]Javascript中的mutators

    本文翻译youtube上的up主kudvenkat的javascript tutorial播放单 源地址在此: https://www.youtube.com/watch?v=PMsVM7rjupU& ...

  7. Chrome Plugin Recommendation

    1.AdBlock 拦截广告神器 2.IPBlade 变更IP地址,使你自由 3.JSON-handle 让接口返回的JSON数据更好看 4.Proxy SwitchyOmega 变更浏览器代理 5. ...

  8. .net 索引器

    索引器允许类或结构的实例就像数组一样进行索引. 索引器类似于属性,不同之处在于它们的访问器采用参数. 在下面的示例中,定义了一个泛型类,并为其提供了简单的 get 和 set 访问器方法(作为分配和检 ...

  9. ElementUI的表单和vee-validate结合使用时发生冲突的解决

    在Vue项目中使用ElementUI表单时,同时又引入了vee-validate进行使用的时候,在浏览器上会出现这样的报错: [Vue warn]: The computed property &qu ...

  10. C#数据类型及差异(复习专用)

    一.数据类型 值类型 类型 描述 范围 默认值 bool 布尔值 True 或 False False byte 8 位无符号整数 0 到 255 0 char 16 位 Unicode 字符 U + ...