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. Spring(二)之配置.md

    依赖配置详解 bean的属性及构造器参数既可以引用容器中的其他bean,也可以是内联(inline)bean.在spring的XML配置中使用 直接变量(基本类型.Strings类型等.) <v ...

  2. 【Maven】解决linux下安装maven update-alternative --display mvn链接层数过多

    问题描述: 今天首次在linux上安装配置maven,编辑/etc/profile 配置好环境变量之后 使用mvn -v 显示出mvn配置信息,此时以为可以顺利的构建maven项目. 结果中间构建时, ...

  3. new 、 delete 、 malloc 、 free 关系

    1.new . delete . malloc . free 关系 delete 会调用对象的析构函数 , 和 new 对应, free 只会释放内存, new 调用构造函数. malloc 与 fr ...

  4. Win7桌面底部的任务栏高度的修改

    Win7桌面底部的任务栏高度的修改.. ----------win7中,任务栏比较宽,有些用户的电脑分辨率比较低,就显得非常占地方,这时可将任务设置成窄模式,图标小图标.鼠标移动到状态上,点击右键.- ...

  5. C++读取csv表格文件到vector

    这个CSV文件假设知道每行有多少个数,也知道数据的格式,即可使用下面简单的方法实现. 我们假设每行有4个数据,依次是int,int,float,float 基本思路是:把每行的数据定为一个类型,放在v ...

  6. HBRUSH to RGB value

    GetObject函数返回一个LOGBRUSH结构体,包含了COLORREF结构. LOGBRUSH lgbrush; COLORREF color; GetObject((HBRUSH)GetSto ...

  7. PyQt5实现透明电子时钟

    # -*- coding: utf-8 -*- import sys from PyQt5 import QtCore from PyQt5 import QtGui from PyQt5 impor ...

  8. 通过H5的新标签canvas做出一个时钟的全过程,希望对初学者有帮助

    最近学习了H5中的一个新标签canvas并且用它做出了一个时钟,最下面是成品图像,还不错吧,这只是我学习中的一个小demo,做得有点粗糙,但终究是做出来了,以后再写自己的网页主页再做一个好看点放上去. ...

  9. 面试题收集---grep和find的区别

    grep是通过文件找内容 find 是通过内容找文件 Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来. 而linux下的find, 在目录结构 ...

  10. CurrentCulture和CurrentUICulture的区别

    CurrentCulture 这个属性用来表示和改变使用者要使用的“地区属性”,地区属性改变后,数字.日期时间等表示格式也随之改变. 注意:一定是“地区属性”,如"zh-cn".& ...