Pandas Series数据结构基本操作
>>> 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数据结构基本操作的更多相关文章
- 02. Pandas 1|数据结构Series、Dataframe
1."一维数组"Series Pandas数据结构Series:基本概念及创建 s.index . s.values # Series 数据结构 # Series 是带有标签的一 ...
- pandas的数据结构之series
Pandas的数据结构 1.Series Series是一种类似于一维数组的对象,由下面两个部分组成: index:相关的数据索引标签 values:一组数据(ndarray类型) series的创建 ...
- pandas中数据结构-Series
pandas中数据结构-Series pandas简介 Pandas是一个开源的,BSD许可的Python库,为Python编程语言提供了高性能,易于使用的数据结构和数据分析工具.Python与Pan ...
- Pandas数据结构(一)——Pandas Series
Pandas 是 Python 中基于Numpy构建的数据操纵和分析软件包,包含使数据分析工作变得快速简洁的高级数据结构和操作工具.通过Pandas Series 和 Pandas DataFrame ...
- Pandas 的数据结构
Pandas的数据结构 导入pandas: 三剑客 from pandas import Series,DataFrame import pandas as pd import numpy as np ...
- Pandas的使用(3)---Pandas的数据结构
Pandas的使用(3) Pandas的数据结构 1.Series 2.DataFrame
- Pandas之数据结构
pandas入门 由于最近公司要求做数据分析,pandas每天必用,只能先跳过numpy的学习,先学习大Pandas库 Pandas是基于Numpy构建的,让以Numpy为中心的应用变得更加简单 pa ...
- Pandas常用数据结构
Pandas 概述 Pandas(Python Data Analysis Library)是基于NumPy 的一种工具,该工具是为了解决数据分析任务而创建的.Pandas 纳入了大量库和一些标准的数 ...
- Pandas——Series and DataFrane
数据科学--pandas库 pandas中有两个主要的数据结构,一个是Series,另一个是DataFrame.通过这两类数据,可以下载数据.可视化数据.和分析数据. Pandas安装:pip ins ...
随机推荐
- 关于Java中编码集的有趣现象和解释
这是在整理另一篇博客的时候发现的一个有趣的现象,是这样描述的:我们都知道Java默认使用的是UniCode编码集,我们也知道char类型占用两个字节.所以奇怪的现象又发生了(见代码): @Test p ...
- 【Python—字典的用法】找到多个字典的公共键
有 a,b,c,d,e,f 6名球员,他们在三轮比赛中的进球数用 s1,s2,s3 3个字典表示,找到每轮都有进球的球员? 创建 s1,s2,s3 3个字典素材 from random import ...
- How To Release and/or Renew IP Addresses on Windows XP | 2000 | NT
Type 'ipconfig' (without the quotes) to view the status of the computer's IP address(es). If the com ...
- Using-JSONNET-for-dynamic-JSON-parsing
原文 https://weblog.west-wind.com/posts/2012/Aug/30/Using-JSONNET-for-dynamic-JSON-parsing With the re ...
- queue队列消费者生产者测试
from multiprocessing import JoinableQueue from threading import Thread def worker(q): while True: tr ...
- MySQL 基础 20191025
1.MySQL(绿色软件)的安装后: (老师课件中的) 要设置字符集不然会报 1344 错误码,有两种: 为上面的还有一种为: set names 'utf8'; 2.MySQL管理 创建数据库 CR ...
- Mac 电脑如何卸载 重装node
由于在日常开发中,部分node版本不支持,因此,我们需要对已安装的node进行卸载重装,步骤如下: 一.在终端依次输入以下命令 sudo npm uninstall npm -g sudo r ...
- Redis 设置权限密码,以及如何开启关闭设置
linux redis 设置密码: 在服务器上,这里以linux服务器为例,为redis配置密码. 1.第一种方式 (当前这种linux配置redis密码的方法是一种临时的,如果redis重启之后 ...
- expdp和impdp
前言 一句话 expdp和impdp,只能在本地服务器运行 使用前 1.创建逻辑目录,该命令不会在操作系统创建真正的目录,最好以system等管理员创建. create directory dpd ...
- 学习selenium grid记录
1.找两台Windows系统,一个是A,作为Hub:一个是B,作为Node: 2.在A.B两台电脑分别下载selenium-server-standalone-2.48.0.jar,并放到指定目录 3 ...