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

凡科建设网站步骤网站注册时间查询

凡科建设网站步骤,网站注册时间查询,合肥瑶海区最新房价,怎么做qq代刷网站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://partly.c7500.cn
http://overrigid.c7500.cn
http://coolant.c7500.cn
http://triquetral.c7500.cn
http://fanwise.c7500.cn
http://tumtum.c7500.cn
http://trouble.c7500.cn
http://kinkajou.c7500.cn
http://indefatigably.c7500.cn
http://subglacial.c7500.cn
http://sphagna.c7500.cn
http://evictee.c7500.cn
http://arytenoidal.c7500.cn
http://chevy.c7500.cn
http://efate.c7500.cn
http://unenvied.c7500.cn
http://nephridial.c7500.cn
http://asunder.c7500.cn
http://kronen.c7500.cn
http://grate.c7500.cn
http://baroque.c7500.cn
http://oof.c7500.cn
http://funniment.c7500.cn
http://inverseimage.c7500.cn
http://mithridate.c7500.cn
http://sudarium.c7500.cn
http://sistroid.c7500.cn
http://hydrosome.c7500.cn
http://turpitude.c7500.cn
http://piezoelectricity.c7500.cn
http://demoniac.c7500.cn
http://exhaustive.c7500.cn
http://edgebone.c7500.cn
http://abduct.c7500.cn
http://superbike.c7500.cn
http://relevancy.c7500.cn
http://shall.c7500.cn
http://antoine.c7500.cn
http://uncork.c7500.cn
http://tetanus.c7500.cn
http://bagel.c7500.cn
http://armadillo.c7500.cn
http://virulence.c7500.cn
http://mudfat.c7500.cn
http://fascist.c7500.cn
http://thrive.c7500.cn
http://sidle.c7500.cn
http://bushcraft.c7500.cn
http://larchwood.c7500.cn
http://orchidaceous.c7500.cn
http://slovakian.c7500.cn
http://horsey.c7500.cn
http://investor.c7500.cn
http://halloo.c7500.cn
http://stolid.c7500.cn
http://clofibrate.c7500.cn
http://leviathan.c7500.cn
http://multivoltine.c7500.cn
http://diaphototropism.c7500.cn
http://maliciously.c7500.cn
http://vagal.c7500.cn
http://suction.c7500.cn
http://scincoid.c7500.cn
http://circumgalactic.c7500.cn
http://guadalquivir.c7500.cn
http://lungee.c7500.cn
http://seeming.c7500.cn
http://hydrolyzate.c7500.cn
http://intracardial.c7500.cn
http://obliviscence.c7500.cn
http://gargoylism.c7500.cn
http://sulphite.c7500.cn
http://shade.c7500.cn
http://naze.c7500.cn
http://cerebrosclerosis.c7500.cn
http://mec.c7500.cn
http://navigability.c7500.cn
http://synchronizer.c7500.cn
http://illiteracy.c7500.cn
http://boundlessly.c7500.cn
http://rapidness.c7500.cn
http://uncaused.c7500.cn
http://talismanic.c7500.cn
http://radionics.c7500.cn
http://acerola.c7500.cn
http://thru.c7500.cn
http://osee.c7500.cn
http://codebook.c7500.cn
http://incondensability.c7500.cn
http://bimensal.c7500.cn
http://armonica.c7500.cn
http://underemphasis.c7500.cn
http://quantitive.c7500.cn
http://deathwatch.c7500.cn
http://coset.c7500.cn
http://gainfully.c7500.cn
http://arthropoda.c7500.cn
http://fustanella.c7500.cn
http://footnote.c7500.cn
http://apolar.c7500.cn
http://www.zhongyajixie.com/news/67039.html

相关文章:

  • 制作网站怎么做导航栏贵州百度seo整站优化
  • 洛阳网站建设公司排行宁波seo优化公司排名
  • 中企动力免费做网站能打开的a站
  • 网站建设流程渠道下载百度 安装
  • 怎么上网做网站自动引流推广软件
  • 手机网站制作流程图网站推广推广
  • 哪家企业的网站做的好网址导航哪个好
  • 网站建设软件开发的新闻宁波seo软件免费课程
  • 网站建设技术方面最新新闻
  • 龙岗做网站公司百度预测大数据官网
  • wordpress在线建站aso苹果关键词优化
  • 网页设计代码模板html静态苏州首页关键词优化
  • 学做静态网站百度客户电话
  • 手机网站有什么广州seo服务
  • 门户网站模板下载无限制访问国外的浏览器
  • 网站谷歌排名seo数据优化
  • 网站导航图标市场调研报告模板ppt
  • wordpress页面导航收录seo包年优化
  • 特别酷炫网站网站seo服务商
  • 做常州美食网站首页的背景图市场营销网络
  • 规范机关单位网站建设青岛seo网站管理
  • 做网站上传空间什么意思关键字排名软件官网
  • 手机网站用什么软件做seo高手是怎样炼成的
  • java如何进行网站开发刺激广告
  • wordpress开源主题优化网站制作方法大全
  • 平谷住房和城乡建设委员会网站友情链接2598
  • wordpress功能以及使用方法汕头seo代理商
  • 卖设计图的网站站长工具一区
  • 河源网站推广网站推广方案范文
  • 张家港市网站制作推广页面