panda库2
>>> a=pd.Series([1,2],index=['a','b'])
>>> a
a 1
b 2
dtype: int64
>>> b=pd.Series(['b','a'])
>>> b
0 b
1 a
dtype: object
>>> 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
>>> dic={'zhang':1,'li':2}
>>> d=pd.Series(dic) 参数的形式是字典,numpy中参数是列表
>>> d
li 2
zhang 1
dtype: int64
>>> frame=pd.DataFrame('name':['zhang','li'],'age':[12,13],'addr':['beijing','shanghai'])
SyntaxError: invalid syntax
>>> dic={'name':['zhang','li'],'age':[12,13],'addr':['beijing','shanghai']}
>>> frame=pd.DataFrame(dic) 参数是字典
>>> frame
addr age name
0 beijing 12 zhang
1 shanghai 13 li
>>> frame.columns index,columns两个关键字属性
Index(['addr', 'age', 'name'], dtype='object')
>>> frame.index
RangeIndex(start=0, stop=2, step=1)
>>> frame2=pd.DataFrame(np.arange(16).reshape((4,4)),colums=['name','age','addr'],index=['a','b','c'])
>>> frame2
like name age addr
a 0 1 2 3
b 4 5 6 7
c 8 9 10 11
d 12 13 14 15
>>> frame.name 指定列名字
0 zhang
1 li
Name: name, dtype: object
>>> frame2.ix[2] 查看某行 ix【】
like 8
name 9
age 10
addr 11
Name: c, dtype: int32
>>> frame2.ix[2,3]
11
>>> frame2.index.name='id';frame2.columns.name='item' 对标头的name属性指定
>>> frame2
item like name age addr
id
a 0 1 2 3
b 4 5 6 7
c 8 9 10 11
d 12 13 14 15
>>> frame2['new']=12 添加新列
>>> frame2
item like name age addr new
id
a 0 1 2 3 12
b 4 5 6 7 12
c 8 9 10 11 12
d 12 13 14 15 12
>>> frame2['new']
id
a 12
b 12
c 12
d 12
Name: new, dtype: int64
>>> frame2['new']['b'] 根据列行找到元素
12
>>> frame2.isin([2])
item like name age addr new
id
a False False True False False
b False False False False False
c False False False False False
d False False False False False
>>> del frame['new']
>>> del frame2['new'] 删除列
>>> frame2
item like name age addr
id
a 0 1 2 3
b 4 5 6 7
c 8 9 10 11
d 12 13 14 15
>>> frame2[frame2<8] 找到小于8的所有元素
item like name age addr
id
a 0.0 1.0 2.0 3.0
b 4.0 5.0 6.0 7.0
c NaN NaN NaN NaN
d NaN NaN NaN NaN
>>> frame.T 对表进行转置
0 1
addr beijing shanghai
age 12 13
name zhang li
>>> frame2.T
id a b c d
item
like 0 4 8 12
name 1 5 9 13
age 2 6 10 14
addr 3 7 11 15
>>> frame2.idxmin() 找到索引的最小值 idxmin()
item
like a
name a
age a
addr a
dtype: object
>>> frame2.idxmax()
item
like d
name d
age d
addr d
dtype: object
>>> frame2.index.is_unique
True
>>> frame2.reindex(['one','two','three','four'])
item like name age addr
id
one NaN NaN NaN NaN
two NaN NaN NaN NaN
three NaN NaN NaN NaN
four NaN NaN NaN NaN
>>> frame2
item like name age addr
id
a 0 1 2 3
b 4 5 6 7
c 8 9 10 11
d 12 13 14 15
>>> frame2.drop('a') 删除行根据索引
item like name age addr
id
b 4 5 6 7
c 8 9 10 11
d 12 13 14 15
>>> frame2.drop(['name'],axis=1) 删除列
item like age addr
id
a 0 2 3
b 4 6 7
c 8 10 11
d 12 14 15
>>> frame2
item like name age addr 每行-series
id
a 0 1 2 3
b 4 5 6 7
c 8 9 10 11
d 12 13 14 15
>>> ser=[1,2,3,4]
>>> frame2-ser
item like name age addr
id
a -1 -1 -1 -1
b 3 3 3 3
c 7 7 7 7
d 11 11 11 11
>>> np.sqrt(frame2) 求所有的sqrt
item like name age addr
id
a 0.000000 1.000000 1.414214 1.732051
b 2.000000 2.236068 2.449490 2.645751
c 2.828427 3.000000 3.162278 3.316625
d 3.464102 3.605551 3.741657 3.872983
>>> f=lambda x:x.max()-x.min() 对frame f(x)默认是对一列的所有值中寻找
>>> frame2.apply(f)
item
like 12
name 12
age 12
addr 12
dtype: int64
>>> def f(x):
return pd.Series([x.min(),x.max()],index=['min','max']) >>> frame.apply(f)
addr age name
min beijing 12 li
max shanghai 13 zhang
>>> frame2.sum()
item
like 24
name 28
age 32
addr 36
dtype: int64
>>> frame.mean()
age 12.5
dtype: float64
>>> frame2.mean()
item
like 6.0
name 7.0
age 8.0
addr 9.0
dtype: float64
>>> frame2.describe()
item like name age addr
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
>>> frame.describe()
age
count 2.000000
mean 12.500000
std 0.707107
min 12.000000
25% 12.250000
50% 12.500000
75% 12.750000
max 13.000000
>>> frame2.sort_index()
item like name age addr
id
a 0 1 2 3
b 4 5 6 7
c 8 9 10 11
d 12 13 14 15
>>> frame.sort_index() 以索引进行排序
addr age name
0 beijing 12 zhang
1 shanghai 13 li
>>> frame
addr age name
0 beijing 12 zhang
1 shanghai 13 li
>>> ser.sort_index()
Traceback (most recent call last):
File "<pyshell#95>", line 1, in <module>
ser.sort_index()
AttributeError: 'list' object has no attribute 'sort_index'
>>> ser
[1, 2, 3, 4, 5]
panda库2的更多相关文章
- python数据分析panda库
panda内有两种数据结构,Series()和DataFrame() >>> a=pd.Series([1,2],index=['a','b']) >>> a a ...
- panda库------对数据进行操作---合并,转换,拼接
>>> frame2 addr age name 0 beijing 12 zhang 1 shanghai 24 li 2 hangzhou 24 cao >>> ...
- python panda库自动去重
http://blog.csdn.net/xinxing__8185/article/details/48022401
- Python数据分析numpy库
1.简介 Numpy库是进行数据分析的基础库,panda库就是基于Numpy库的,在计算多维数组与大型数组方面使用最广,还提供多个函数操作起来效率也高 2.Numpy库的安装 linux(Ubuntu ...
- 3 个用于数据科学的顶级 Python 库
使用这些库把 Python 变成一个科学数据分析和建模工具. Python 的许多特性,比如开发效率.代码可读性.速度等使之成为了数据科学爱好者的首选编程语言.对于想要升级应用程序功能的数据科学家和机 ...
- 程序员用于机器学习数据科学的3个顶级 Python 库
NumPy NumPy(数值 Python 的简称)是其中一个顶级数据科学库,它拥有许多有用的资源,从而帮助数据科学家把 Python 变成一个强大的科学分析和建模工具.NumPy 是在 BSD 许可 ...
- Python爬虫作业
题目如下: 请分析作业页面(https://edu.cnblogs.com/campus/hbu/Python2018Fall/homework/2420), 爬取已提交作业信息,并生成已提 ...
- Python数据分析之双色球高频数据统计
Step1:基础数据准备(通过爬虫获取到),以下是从第一期03年双色球开奖号到今天的所有数据整理,截止目前一共2549期,balls.txt 文件内容如下 : 备注:想要现成数据的可以给我发邮件哟~ ...
- sql mysql数据库导库 panda pymysql
mysql数据库 导入数据 1. panda 效率超高 对内存要求高 网络稳定性 # 读取文件 ratings_names = ['user_id', 'movie_id', 'ratings', ' ...
随机推荐
- Java微信公众平台开发之获取地理位置
本部分需要用到微信的JS-SDK,微信JS-SDK是微信公众平台面向网页开发者提供的基于微信内的网页开发工具包.通过使用微信JS-SDK,网页开发者可借助微信高效地使用拍照.选图.语音.位置等手机系统 ...
- SQL中多条件查询括号的用途
界面: 代码 0 posted @ 2009-12-15 13:28 唔愛吃蘋果 阅读(8640) 评论(0) 编辑 收藏
- Ext.NET webform
Ext.NET是基于跨浏览器的ExtJS库和.NET Framework的一套支持ASP.NET AJAX的非开源Web控件,包含有丰富的Ajax运用,其前身是Coolite[1] .
- 01、Mybatis快速入门
MyBatis是一个支持普通SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis消除了几乎所有的JDBC代码和参数的手工设置以及对结果集的检索封装.MyBatis可以使用简单的XML或注解用 ...
- G++与VS2015在变量作用域上的差异性
前段时间,发现同一段C++代码在windows .Linux下的运行结果居然不一样,于是测试了一把. 我们都知道,C++中不同作用域中不同的变量是互不干扰的,可以在全局作用域.函数作用域声明同样名字的 ...
- LAMP环境的搭建(一)----Apache安装
centos是Linux发行版RedHat的一个分支,因此可以很方便的使用yum安装并管理各种软件包. 本文使用的系统环境为:阿里云Centos7.2. Apache的安装: 输入命令: yum –y ...
- Microsoft Azure Storage Exployer使用指南
概述 Microsoft Azure Storage Exployer 是微软官方推荐的一款管理Azure Storage 客户端工具,客户使用完全免费.支持Windows.Mac和Linux.用户使 ...
- poj2051 Argus
Description A data stream is a real-time, continuous, ordered sequence of items. Some examples inclu ...
- httpclient 学习
Http协议的重要性相信不用我多说了,HttpClient相比传统JDK自带的URLConnection,增加了易用性和灵活性,它不仅是客户端发送Http请求变得容易,而且也方便了开发人员测试接口(基 ...
- 使用Groovy处理SoapUI中Json response
最近工作中,处理最多的就是xml和json类型response,在SoapUI中request里面直接添加assertion处理json response的话,可以采用以下方式: import gro ...