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', ' ...
随机推荐
- EF vs ADO.NET
EF有什么缺点,什么时候需要考虑用ADO.NET http://blog.sina.com.cn/s/blog_4aedf6370102wgxl.html
- 给出打印结果-setTimeout
问题: 请给出打印结果: for(var i=0;i<5;i++){ setTimeout(function(){ console.log(i); },0); } 解析: 考的是setTimeo ...
- jFreeChart利用CategoryDatase,ChartFactory.createBarChart生成的柱状图
package com.potevio.rnd; import java.io.File; import java.io.FileNotFoundException; import java.io.F ...
- 记一次VS Code崩溃的解决(Win10扫描自动回复系统文件)
早上修改Vue.js框架搭建的项目,正高兴着,突然电脑崩溃,重启后VS code打不开,报错如下: DWrite.dll丢失 然后查看了一下 C:\windows\system32\下 DWrite ...
- shell流程控制--循环语句
#!/bin/bash ### for循环,数字段形式 echo 'for 循环,数字段形式' ..} do echo $i done ### for 循环,双括号形式 echo 'for 循环,双括 ...
- 使用TenforFlow 搭建BP神经网络拟合二次函数
使用简单BP神经网络拟合二次函数 当拥有两层神经元时候,拟合程度明显比一层好 并出现如下警告: C:\Program Files\Python36\lib\site-packages\matplotl ...
- 卸载oracle 11g数据库
完全卸载oracle11g步骤:1. 开始->设置->控制面板->管理工具->服务 停止所有Oracle服务.2. 开始->程序->oracle - OraHome ...
- 计算机程序的思维逻辑 (95) - Java 8的日期和时间API
本节继续探讨Java 8的新特性,主要是介绍Java 8对日期和时间API的增强,关于日期和时间,我们在之前已经介绍过两节了,32节介绍了Java 1.8以前的日期和时间API,主要的类是Date和 ...
- 两个input在同一行连着不留缝隙
方法1:让两个input 连在一起写 不换行 <div class="inputDiv"> <input type="text" placeh ...
- C++中4个类型转换相关的关键字/特点/应用场合
reinterpret_cast是C++里面的一个强制类型转换符,能够将任何的指针类型转换成其他的任何指针类型:能够将任何的整数类型转换成指针类型,反之亦然:滥用reinterpret_cast强制类 ...