1.DataFrame的常用函数: 
(1)np.abs(frame) 绝对值,
(2)apply function,
  lambda f= lambda x: x.max()-x.min(),frame.apply(f); frame.apply(f,axis = 1)
  f(x), def f(x):
      return Series([x.min(),x.max()], index=['min','max']),frame.apply(f)
(3) applymap format
  f= lambda x:'%.2f' %x, frame.applymap(f) 或者 frame['e'].map(format)
2. index 或者 column的排序
行排序:frame.sort_index()
列排序:frame.sort_index(axis=1)
列降序排列:frame.sort_index(axis=1,ascending=False)
通过值进行排序:
Series.sort_values()
frame.sort_values(by = 'b')
frame.sort_values(by = ['a','b'])
3.
排名(Series.rank(method='average', ascending=True))的作用与排序的不同之处在于,
他会把对象的 values 替换成名次(从 1 到 n)。这时唯一的问题在于如何处理平级项,方法里的 method 参数就是起这个作用的,
他有四个值可选:average, min, max, first
Series.rank()
frame.rank(axis=1) 按照columns 进行排序。
4.

'''function application and mapping'''
import numpy as np
from pandas import DataFrame , Series
frame = DataFrame(np.random.randn(4, 3), columns=list('bde'), index=['Utah', 'Ohio', 'Texas', 'Oregon'])
print("frame is \n", frame)
print("np.abs(frame) is \n", np.abs(frame))
print("another frequent operation is applying a function on 1D arrays to each column or row.\n DataFrame's apply method does exactly this:")
f = lambda x: x.max()-x.min()
print("f = lambda x: x.max()-x.min()")
print("frame.apply(f):", frame.apply(f))
print("frame.apply(f,axis=1):",frame.apply(f,axis=1))
def f(x):
return Series([x.min(), x.max()], index=['min', 'max'])
print("frame.apply(f): \n", frame.apply(f))
print("the function pass to apply need not to return a scalar value,it can also return a series with multiple values") format = lambda x: '%.2f' % x
print("frame.applymap(format): \n", frame.applymap(format))
print("frame['e'].map(format): \n", frame['e'].map(format))
obj = Series(range(4),index=['d', 'a', 'b', 'c'])
print("obj.sort_index: \n", obj.sort_index()) frame = DataFrame(np.arange(8).reshape((2, 4)), index=['three', 'one'], columns= ['d', 'a', 'b', 'c'])
print("frame is \n", frame)
print("frame.sort_index() \n", frame.sort_index())
print("frame.sort_index(axis=1) \n", frame.sort_index(axis=1)) print("frame.sort_index(axis=1,ascending=False): \n", frame.sort_index(axis=1,ascending=False))
obj= Series([4, 7, -3, 2])
print("obj: \n", obj)
print("obj.sort_values(): \n", obj.sort_values()) obj1 = Series([4, np.nan, 7, np.nan, -3, 2])
print("obj1:",obj1)
print("obj1.sort_values():\n", obj1.sort_values()) frame1 = DataFrame({'b':[4,7,-3,2],'a':[0,1,0,1]})
print("frame1 is \n",frame1)
print("frame1.sort_values(by='b')\n",frame1.sort_values(by='b'))
print("frame1.sort_values(by=['a','b'] \n", frame1.sort_values(by=['a','b'])) print("Ranking is closely related to sorting,assigning ranks from one through the number of valid data points in an array")
obj2 = Series([7, -5, 7, 4, 2, 0, 4])
print("obj2.rank() is \n", obj2.rank())

obj2 = Series([7, -5, 7, 4, 2, 0, 4])
print("obj2.rank() is \n", obj2.rank())
print("obj2.rank(method='min') \n",obj2.rank(method='min'))
print("obj2.rank(method='max') \n",obj2.rank(method = 'max'))
print("obj2.rank(method='first' \n",obj2.rank(method = 'first'))
print("obj2.rank(method='dense' \n", obj2.rank(method = 'dense')) frame2 = DataFrame({'b':[4.3, 7, -3,2],'a':[0,1,0,1],'c':[-2,5,8,-2.5]})
print("frame2 is \n",frame2)
print("frame2.rank(axis=1) \n",frame2.rank(axis=1))
												

最新文章

  1. git 实用技巧
  2. Csstyle - 创建简洁、可维护强的 CSS 样式
  3. Thread create 创建进程
  4. DNS为什么通常都会设置为14.114.114.114
  5. Winform之SpreadSheetGear转DevExpress.XtraSpreadsheet.v13.2 z
  6. Yii CModel中rules验证规则
  7. 【高斯消元】BZOJ 1770: [Usaco2009 Nov]lights 燈
  8. Win7下安装Mongodb教程
  9. jquery中onclick内$(this)指向
  10. I2C总线之(三)---以C语言理解IIC
  11. A Bit Of Knowledge
  12. C# NameValueCollection集合 .
  13. zoj 3706 Break Standard Weight
  14. 浅谈PHP7的新特性
  15. php 变量原理讲解
  16. 记一个 dubbo中hessian2反序列化 Map 的一个问题
  17. React 中的this.setState
  18. WordPress版微信小程序3.0版发布
  19. JSP内置对象——pageContext对象和config对象
  20. Python学习-终端字体高亮显示1

热门文章

  1. 使用selenium找出外卖点餐次数最多的10个顾客
  2. tkprof参数详解
  3. execute sp_executesql 用变量获取返回值
  4. 为什么mysql innodb索引是B+树数据结构
  5. Linux系统——date命令
  6. [Windows Powershell]-学习笔记(4)
  7. sgu 101 Domino 解题报告及测试数据
  8. 使用Node.js快速搭建简单的静态文件服务器
  9. Windows MFC控件消息编程
  10. java并发编程与高并发解决方案