>>> import pandas
>>> import numpy as np
>>> from pandas import Series,DataFrame
#define a series without assigned index
>>> obj = Series([1,-5,7,3])
>>> print obj
0 1
1 -5
2 7
3 3
dtype: int64
>>> print obj.index
RangeIndex(start=0, stop=4, step=1)
>>> print obj.values
[ 1 -5 7 3]
>>> print obj[3]
3 #explicitly assigned index dbac
>>> obj1 = Series([1,2,3,4],index=['d','b','a','c'])
>>> print obj1
d 1
b 2
a 3
c 4
dtype: int64
>>> print obj1.values
[1 2 3 4]
>>> print obj1.index
Index([u'd', u'b', u'a', u'c'], dtype='object')
>>> print obj1['c']
4
>>> obj1['a']=-4
>>> print obj1.values
[ 1 2 -4 4] #basic operation, index will not be changed
>>> obj1[obj1>0]
d 1
b 2
c 4
dtype: int64
>>> print obj1
d 1
b 2
a -4
c 4
dtype: int64
>>> obj2 = obj1[obj1>0]
>>> obj2
d 1
b 2
c 4
dtype: int64
>>> obj2*2
d 2
b 4
c 8
dtype: int64
>>> obj2
d 1
b 2
c 4
dtype: int64
>>> obj2 = obj2*2
>>> obj2
d 2
b 4
c 8
dtype: int64
>>> obj2=np.exp(obj2)
>>> obj2
d 7.389056
b 54.598150
c 2980.957987
dtype: float64
>>> 'b' in obj2
True
>>> 'e' in obj2
False

给Series赋值index和values

#define a Series with indexes and values
>>> sdata={'beijing':'010','shanghai':'021','guangdong':'020'}
>>> obj3 = Series(sdata)
>>> print obj3
beijing 010
guangdong 020
shanghai 021
dtype: object
>>> index1 = ['tianjin','shanghai','guangdong','beijing']
>>> obj3 = Series(sdata,index=index1)
>>> print obj3
tianjin NaN
shanghai 021
guangdong 020
beijing 010
dtype: object #isnull or notnull
>>> import pandas as pd
>>> print pd.isnull(obj3)
tianjin True
shanghai False
guangdong False
beijing False
dtype: bool
>>> print pd.notnull(obj3)
tianjin False
shanghai True
guangdong True
beijing True
dtype: bool

将乱序索引的两个Series根据索引相加

>>> obj3 = Series(sdata)
>>> print obj3
beijing 010
guangdong 020
shanghai 021
dtype: object
>>> index1 = ['tianjin','shanghai','guangdong','beijing']
>>> obj4 = Series(sdata,index=index1)
>>> print obj4
tianjin NaN
shanghai 021
guangdong 020
beijing 010
dtype: object
>>> print obj3+obj4
beijing 010010
guangdong 020020
shanghai 021021
tianjin NaN
dtype: object

Series name and index name

>>> obj4.name='postcode'
>>> obj4.index.name='city'
>>> print obj4
city
tianjin NaN
shanghai 021
guangdong 020
beijing 010
Name: postcode, dtype: object

Pandas Series数据结构基本操作的更多相关文章

  1. 02. Pandas 1|数据结构Series、Dataframe

    1."一维数组"Series Pandas数据结构Series:基本概念及创建 s.index  . s.values # Series 数据结构 # Series 是带有标签的一 ...

  2. pandas的数据结构之series

    Pandas的数据结构 1.Series Series是一种类似于一维数组的对象,由下面两个部分组成: index:相关的数据索引标签 values:一组数据(ndarray类型) series的创建 ...

  3. pandas中数据结构-Series

    pandas中数据结构-Series pandas简介 Pandas是一个开源的,BSD许可的Python库,为Python编程语言提供了高性能,易于使用的数据结构和数据分析工具.Python与Pan ...

  4. Pandas数据结构(一)——Pandas Series

    Pandas 是 Python 中基于Numpy构建的数据操纵和分析软件包,包含使数据分析工作变得快速简洁的高级数据结构和操作工具.通过Pandas Series 和 Pandas DataFrame ...

  5. Pandas 的数据结构

    Pandas的数据结构 导入pandas: 三剑客 from pandas import Series,DataFrame import pandas as pd import numpy as np ...

  6. Pandas的使用(3)---Pandas的数据结构

    Pandas的使用(3) Pandas的数据结构 1.Series 2.DataFrame

  7. Pandas之数据结构

    pandas入门 由于最近公司要求做数据分析,pandas每天必用,只能先跳过numpy的学习,先学习大Pandas库 Pandas是基于Numpy构建的,让以Numpy为中心的应用变得更加简单 pa ...

  8. Pandas常用数据结构

    Pandas 概述 Pandas(Python Data Analysis Library)是基于NumPy 的一种工具,该工具是为了解决数据分析任务而创建的.Pandas 纳入了大量库和一些标准的数 ...

  9. Pandas——Series and DataFrane

    数据科学--pandas库 pandas中有两个主要的数据结构,一个是Series,另一个是DataFrame.通过这两类数据,可以下载数据.可视化数据.和分析数据. Pandas安装:pip ins ...

随机推荐

  1. 1.OpenCV数据类型

    基础类型 1.模板类cv::Vec<> 固定向量类,维度已知的小型向量——处理效率高 2.cv::Point类(Point2i,Point2f,Point2d;Point3i,Point3 ...

  2. cita 源码研究

    适用环境 vim + YouCompleteMe 使用 github 源,不能使用 ustc 源 git clone --depth 1 --recusive https://github.com/k ...

  3. VLAN基础配置及Access接口

    一.实验目的 二.实验拓扑图 三.实验编址 四.实验步骤 1.基础配置 按照PC1的方式依次配好IP 打开所有设备 用ping命令测试连通性 更改主机名称 2.创建VLAN 在S1上使用两条命令创建V ...

  4. 第十三周学习总结&实验报告(八)

    图像界面 件处理及监听处理 1.键盘事件(KeyEvent)及监听处理(KeyListener) 1.1加入事件监听 super.addWindowListener(new WindowAdapter ...

  5. HDU 6464 /// 权值线段树

    题目大意: 共Q次操作 操作有两种 操作一 在序列尾部加入f[i]个s[i] 操作二 查询序列第f[i]小到第s[i]小之间的总和 离线操作 把序列内的值离散化 然后利用离散化后的值 在线段树上对应权 ...

  6. 不要62(数位dp)

    题目传送门 不要62 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  7. Logback配置,error和普通日志分离

    <?xml version="1.0" encoding="utf-8"?> <configuration> <springPro ...

  8. C++学习笔记【1】——"\n"与endl的区别是什么?

    #include <iostream> using namespace std; int main() { cout << "Hello, world!" ...

  9. translation of 《deep learning》 Chapter 1 Introduction

    原文: http://www.deeplearningbook.org/contents/intro.html Inventors have long dreamed of creating mach ...

  10. 解决 'express' 不是内部或外部命令,也不是可运行的程序

    express-generator >npm install -g express-generator 就可以了