panda内有两种数据结构,Series()和DataFrame()

 >>> a=pd.Series([1,2],index=['a','b'])
>>> a
a 1
b 2
dtype: int64
 >>> b.index
RangeIndex(start=0, stop=2, step=1)
>>> b.values
array(['b', 'a'], dtype=object)
>>> a/2
a 0.5
b 1.0
dtype: float64
>>>

列表切分选择

>>> s[0:3:2]
a 2
c 6
dtype: int64  
  s3=pd.Series(arr)  另一种方式生成series
>>> s3
0 1
1 2
2 3
3 4
dtype: int32
>>> s3=pd.Series(s)
>>> s3
a 2
b 5
c 6
d 3
dtype: int64
>>> s[s>8]
Series([], dtype: int64)
>>> s
a 2
b 5
c 6
d 3
dtype: int64
>>> s[s>3] 找出>3的元素
b 5
c 6
dtype: int64
>>> np.log(s) 对series直接运用函数
a 0.693147
b 1.609438
c 1.791759
d 1.098612
dtype: float64
>>> s.isin([5,6]) 看某些元素是否在series中,boolean值
a False
b True
c True
d False
dtype: bool
>>> s[s.isin([5,6])]
b 5
c 6
dtype: int64
>>> s2=pd.Series([5,2,np.NaN,7,np.NaN])
>>> s2
0 5.0
1 2.0
2 NaN
3 7.0
4 NaN
dtype: float64
>>> s2.isnull()
0 False
1 False
2 True
3 False
4 True
dtype: bool
>>> s2.notnull()
0 True
1 True
2 False
3 True
4 False
dtype: bool
>>> s2[s2.isnull()]
2 NaN
4 NaN
dtype: float64

Frame的使用

 frame2=pd.DataFrame(fram,columns=['name','age'])
>>> frame2
name age
red 1 2
yellow 5 6
blue 9 10
black 13 14
>>> frame2.values
array([[ 1, 2],
[ 5, 6],
[ 9, 10],
[13, 14]])
>>> frame2.index
Index([u'red', u'yellow', u'blue', u'black'], dtype='object')
>>> frame2.columns
Index([u'name', u'age'], dtype='object')
>>> frame2['name']
red 1
yellow 5
blue 9
black 13
Name: name, dtype: int32
>>> frame2.name
red 1
yellow 5
blue 9
black 13
Name: name, dtype: int32
>>> frame2.age
red 2
yellow 6
blue 10
black 14
Name: age, dtype: int32
>>> frame2[index=['red']]
>>> frame2[0:2]
name age
red 1 2
yellow 5 6
>>> frame2['name'][2]
9
 >>> s.idxmin()
'a'
>>> s.idxmax9)
SyntaxError: invalid syntax
>>> s.idxmax()
'c'
>>> s.index.is_unique
True
>>> fram
id name age home
red 0 1 2 3
yellow 4 5 6 7
blue 8 9 10 11
black 12 13 14 15
>>> frame4=fram.drop(['name','age'],axis=1) 删除列
>>> frame4
id home
red 0 3
yellow 4 7
blue 8 11
black 12 15
 >>> f=lambda x:x.max()-x.min()   对frame运用自定义函数
>>> fram.apply(f)
id 12
name 12
age 12
home 12
dtype: int64
>>> fram.apply(f,axis=1)
red 3
yellow 3
blue 3
black 3
dtype: int64
>>> fram.apply(f,axis=0)
id 12
name 12
age 12
home 12
dtype: int64
>>> def f(x):
return pd.Series([x.min(),x.max()],index=['min','max']) >>> fram.apply(f)
id name age home
min 0 1 2 3
max 12 13 14 15

  frame的一些数学统计值

 >>> fram.describe()
id name age home
count 4.000000 4.000000 4.000000 4.000000
mean 6.000000 7.000000 8.000000 9.000000
std 5.163978 5.163978 5.163978 5.163978
min 0.000000 1.000000 2.000000 3.000000
25% 3.000000 4.000000 5.000000 6.000000
50% 6.000000 7.000000 8.000000 9.000000
75% 9.000000 10.000000 11.000000 12.000000
max 12.000000 13.000000 14.000000 15.000000
>>> fram.sum()
id 24
name 28
age 32
home 36
dtype: int64
>>> fram.mean()
id 6.0
name 7.0
age 8.0
home 9.0
dtype: float64
>>> fram.min()
id 0
name 1
age 2
home 3
dtype: int32

python数据分析panda库的更多相关文章

  1. Python数据分析numpy库

    1.简介 Numpy库是进行数据分析的基础库,panda库就是基于Numpy库的,在计算多维数组与大型数组方面使用最广,还提供多个函数操作起来效率也高 2.Numpy库的安装 linux(Ubuntu ...

  2. Python数据分析扩展库

    Anaconda和Python(x,y)都自带了下面的这些库. 1. NumPy 强大的ndarray和ufunc函数. import numpy as np xArray = np.ones((3, ...

  3. Python数据分析Pandas库方法简介

    Pandas 入门 Pandas简介 背景:pandas是一个Python包,提供快速,灵活和富有表现力的数据结构,旨在使“关系”或“标记”数据的使用既简单又直观.它旨在成为在Python中进行实际, ...

  4. Python数据分析工具库-Numpy 数组支持库(一)

    1 Numpy数组 在Python中有类似数组功能的数据结构,比如list,但在数据量大时,list的运行速度便不尽如意,Numpy(Numerical Python)提供了真正的数组功能,以及对数据 ...

  5. Python数据分析Numpy库方法简介(二)

    数据分析图片保存:vg 1.保存图片:plt.savefig(path) 2.图片格式:jpg,png,svg(建议使用,不失真) 3.数据存储格式: excle,csv csv介绍 csv就是用逗号 ...

  6. 利用python数据分析panda学习笔记之Series

    1 Series a:类似一维数组的对象,每一个数据与之相关的数据标签组成 b:生成的左边为索引,不指定则默认从0开始. from pandas import Series,DataFrame imp ...

  7. Python数据分析Pandas库之熊猫(10分钟二)

    pandas 10分钟教程(二) 重点发法 分组 groupby('列名') groupby(['列名1','列名2',.........]) 分组的步骤 (Splitting) 按照一些规则将数据分 ...

  8. Python数据分析Pandas库之熊猫(10分钟一)

    pandas熊猫10分钟教程 排序 df.sort_index(axis=0/1,ascending=False/True) df.sort_values(by='列名') import numpy ...

  9. Python数据分析Pandas库数据结构(一)

    pandas数据结构 1.生成一维矩阵模拟数据 import pandas as pdimport numpy as nps = pd.Series([1,2,3,4,np.nan,9,9])s2 = ...

随机推荐

  1. asp.net core MVC 全局过滤器之ExceptionFilter异常过滤器(一)

    本系类将会讲解asp.net core MVC中的内置全局过滤器的使用,将分为以下章节 asp.net core MVC 过滤器之ExceptionFilter异常过滤器(一) asp.net cor ...

  2. 如何解决修改AzureVM默认RDP端口后,连不上的问题

    Enter-PSSession -ComputerName 139.219.135.45 -Port 5986 -Authentication Negotiate -Credential 'mssto ...

  3. Struts2之初识

    Struts2教程 第一章 初识Struts2 主页:http://struts.apache.org/ 优势:用户请求,模块处理,页面展现.适用于企业级开发,便于维护. 配置:web.xml中添加的 ...

  4. EasyUI Datagrid 鼠标悬停显示单元格内容

    第一种方式: .js 定义函数 <script type="text/javascript"> //格式化单元格提示信息 function formatCellTool ...

  5. 【Spring 核心】装配bean(二) JavaConfig装配

    前面介绍完了组件扫描和自动装配,这里再来看一下装配bean的另一种方式JavaConfig. 包路径: src/main/java com.bonc-|--config--|--CDPlayerCon ...

  6. JavaScript的8行代码搞定js文件引入问题

    单页面的操作,免不了会有各种jsp的嵌套问题,一个操作页面里面可能涉及到几十甚至上百个jsp页面. 平常我们对用到的js文件的引入,都会放到index的header里面.如图: 但是,让我们思考三个问 ...

  7. 工作中git常用命令

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; line-height: 16.0px; font: 14.0px "PingFang SC" } ...

  8. redis 介绍和常用命令

    redis 介绍和常用命令 redis简介 Redis 是一款开源的,基于 BSD 许可的,高级键值 (key-value) 缓存 (cache) 和存储 (store) 系统.由于 Redis 的键 ...

  9. django富文本编辑器

    -------------------tinymce富文本编辑器1.下载安装 1.在网站pypi网站搜索并下载"django-tinymce-2.4.0" 2.解压:tar zxv ...

  10. java开发网易电话面试 一面总结

    晚上八点多自己在看视频的时候突然接到杭州来的一个电话,当时觉得很奇怪,突兀,接通之后被告知是杭州网易打来的,没有简单的自我介绍,没有多余的废话,直接入主题,吓得我心里怪紧张的,完全没有准备,但是也没有 ...