当前位置: 首页 > news >正文

小女孩做网站php网站怎么做302

小女孩做网站,php网站怎么做302,修改wordpress用户名,番禺外贸网站建设Pandas数据操作 排序操作对索引进行排序按行排序按值排序 删除操作算数运算去重duplicated()drop_duplicates() 数据重塑层次化索引索引方式内层选取数据重塑 排序操作 对索引进行排序 Series 用 sort_index() 按索引排序,sort_values() 按值排序; Dat…

Pandas数据操作

  • 排序操作
    • 对索引进行排序
    • 按行排序
    • 按值排序
  • 删除操作
  • 算数运算
  • 去重
    • duplicated()
    • drop_duplicates()
  • 数据重塑
    • 层次化索引
    • 索引方式
    • 内层选取
    • 数据重塑

排序操作

对索引进行排序

Series 用 sort_index() 按索引排序,sort_values() 按值排序;
DataFrame 也是用 sort_index() 和 sort_values()。

In[73]: obj = Series(range(4), index=['d','a','b','c'])
In[74]: obj.sort_index()  
Out[74]: 
a    1
b    2
c    3
d    0
dtype: int64
In[78]: frame = DataFrame(np.arange(8).reshape((2,4)),index=['three', 'one'],columns=['d','a','b','c'])
In[79]: frame
Out[79]: d  a  b  c
three  0  1  2  3
one    4  5  6  7
In[86]: frame.sort_index()
Out[86]: d  a  b  c
one    4  5  6  7
three  0  1  2  3

按行排序

In[89]: frame.sort_index(axis=1, ascending=False)
Out[89]: d  c  b  a
three  0  3  2  1
one    4  7  6  5

按值排序

Series:

In[92]: obj = Series([4, 7, -3, 2])
In[94]: obj.sort_values()
Out[94]: 
2   -3
3    2
0    4
1    7
dtype: int64

DataFrame:

In[95]: frame = DataFrame({'b':[4, 7, -3, 2], 'a':[0, 1, 0, 1]})
In[97]: frame.sort_values(by='b')  #DataFrame必须传一个by参数表示要排序的列
Out[97]: a  b
2  0 -3
3  1  2
0  0  4
1  1  7

删除操作

删除指定轴上的项
即删除 Series 的元素或 DataFrame 的某一行(列)的意思,我们可以通过对象的 drop(labels, axis=0) 方法实现此功能。

删除 Series 的一个元素:

In[11]: ser = Series([4.5,7.2,-5.3,3.6], index=['d','b','a','c'])
In[13]: ser.drop('c')
Out[13]: 
d    4.5
b    7.2
a   -5.3
dtype: float64

删除 DataFrame 的行或列:

In[17]: df = DataFrame(np.arange(9).reshape(3,3), index=['a','c','d'], columns=['oh','te','ca'])
In[18]: df
Out[18]: oh  te  ca
a   0   1   2
c   3   4   5
d   6   7   8In[19]: df.drop('a')
Out[19]: oh  te  ca
c   3   4   5
d   6   7   8In[20]: df.drop(['oh','te'],axis=1)
Out[20]: ca
a   2
c   5
d   8

需要注意的是 drop() 返回的是一个新对象,原对象不会被改变。

算数运算

DataFrame 中的算术运算是 df 中对应位置的元素的算术运算,如果没有共同的元素,则用 NaN 代替。

In[5]: df1 = DataFrame(np.arange(12.).reshape((3,4)),columns=list('abcd'))
In[6]: df2 = DataFrame(np.arange(20.).reshape((4,5)),columns=list('abcde'))
In[9]: df1+df2
Out[9]: a   b   c   d   e
0   0   2   4   6 NaN
1   9  11  13  15 NaN
2  18  20  22  24 NaN
3 NaN NaN NaN NaN NaN

此外,如果我们想设置默认的其他填充值,而非 NaN 的话,可以传入填充值。

In[11]: df1.add(df2, fill_value=0)
Out[11]: a   b   c   d   e
0   0   2   4   6   4
1   9  11  13  15   9
2  18  20  22  24  14
3  15  16  17  18  19

去重

duplicated()

DataFrame 的 duplicated 方法返回一个布尔型 Series,表示各行是否是重复行。具体用法如下:

In[1]: df = DataFrame({'k1':['one']*3 + ['two']*4, 'k2':[1,1,2,3,3,4,4]})
In[2]: df
Out[2]: k1  k2
0  one   1
1  one   1
2  one   2
3  two   3
4  two   3
5  two   4
6  two   4
In[3]: df.duplicated()
Out[3]: 
0    False
1     True
2    False
3    False
4     True
5    False
6     True
dtype: bool

drop_duplicates()

drop_duplicates() 用于去除重复的行数,具体用法如下:

In[4]: df.drop_duplicates()
Out[4]: k1  k2
0  one   1
2  one   2
3  two   3
5  two   4

数据重塑

层次化索引

层次化索引(hierarchical indexing)是 pandas 的一项重要功能,它使我们能在一个轴上拥有多个(两个以上)索引级别。请看以下例子:

In[1]:data = Series(np.random.randn(10), index = [['a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'd', 'd' ],[1,2,3,1,2,3,1,2,2,3]])
In[2]:data
Out[2]:
a  1    0.1692392    0.6892713    0.879309
b  1   -0.6991762    0.2604463   -0.321751
c  1    0.8931052    0.757505
d  2   -1.2233443   -0.802812
dtype: float64

索引方式

In[3]:data['b':'d']
Out[3]:
b  1   -0.6991762    0.2604463   -0.321751
c  1    0.8931052    0.757505
d  2   -1.2233443   -0.802812
dtype: float64

内层选取

In[4]:data[:, 2]
Out[4]:
a    0.689271
b    0.260446
c    0.757505
d   -1.223344
dtype: float64

数据重塑

将 Series 转化成 DataFrame:

in[5]:data.unstack()
Out[5]:
1                    2            3
a    0.169239    0.689271    0.879309
b    -0.699176   0.260446  -0.321751
c    0.893105    0.757505    NaN
d    NaN        -1.223344   -0.802812
http://www.yayakq.cn/news/393845/

相关文章:

  • 洛阳网站的优化贵阳网站建设怎么样
  • 网店网站技术方案dw是做网站的软件吗
  • 个人创办网站上海建设集团有限公司
  • 网站排行首页怎么做WordPress蜘蛛爬行插件
  • 高能建站系统怎么收费西安建设市场诚信信息平台网站
  • 企业网站建设方案论文做参茸产品的网站
  • 宜昌模板网站建设个人自己免费建网站
  • 济南品牌网站建设价格许昌定制网站建设代理
  • 如何制作视频网站小公司做网站多少钱
  • 做网站需要租服务器么深圳网站 制作信科便宜
  • 做asp网站的步骤网站建设征求意见稿
  • 不会代码建设网站wordpress文字可以动的插件
  • 台州网站排名优化价格邮箱地址注册入口
  • 石材外贸在哪个网站做邯郸哪个公司做网站好
  • wordpress做阿里巴巴国际站便宜高端网站设计推荐
  • 怎样做分销网站旅游区网站开发
  • 网站建设与管理案例教程北京网站推广价格
  • 程序员怎么做网站赚钱网页微信登陆首页
  • 做网站的公司搞什么活动有什么网站可以做初中试题
  • 做网站 用什么语言网站常用的一种js幻灯片
  • 如何开发一个微网站南宁市城市建设档案馆网站
  • 张家口网站建设费用前端 网站开发 常见功能实现
  • 死链对网站的影响东莞制作公司网站
  • 深圳龙岗做网站公司哪家好关于开通网站建设的请示
  • 霞浦建设局网站wordpress百度抓取
  • 洛阳青峰网络公司做网站wordpress 多模板
  • 水利工程建设监理网站全免费自助建站
  • 拐角型布局网站wordpress 媒体文件库
  • 做网站基本流程高端制作网站技术
  • 建站点如何再腾讯云服务器做网站