介紹操作Series和DataFrame中的數(shù)據(jù)的基本功能
重新索引
pandas對象的一個重要方法是reindex,其作用是創(chuàng)建一個適應新索引的新對象鲁猩。以之前的一個簡單示例來說
In [1]: from pandas import Series,DataFrame
In [2]: import pandas as pd
In [3]: import numpy as np
In [4]: obj=Series([6.5,7.8,-5.9,8.6],index=['d','b','a','c'])
In [5]: obj
Out[5]:
d 6.5
b 7.8
a -5.9
c 8.6
dtype: float64
調用該Series的reindex將會根據(jù)新索引進行重排。如果某個索引值當前不存在畴博,就引入缺失值
In [6]: obj2=obj.reindex(['a', 'b', 'c', 'd', 'e'])
In [7]: obj2
Out[7]:
a -5.9
b 7.8
c 8.6
d 6.5
e NaN
dtype: float64
In [8]: obj.reindex(['a', 'b', 'c', 'd', 'e'], fill_value=0)
Out[8]:
a -5.9
b 7.8
c 8.6
d 6.5
e 0.0
dtype: float64
In [9]: obj3=Series(['blue', 'purple', 'yellow'], index=[0, 2, 4])
In [10]: obj3.reindex(range(6), method='ffill')
Out[10]:
0 blue
1 blue
2 purple
3 purple
4 yellow
5 yellow
dtype: object
In [11]: obj3.reindex(range(6), method='bfill')
Out[11]:
0 blue
1 purple
2 purple
3 yellow
4 yellow
5 NaN
dtype: object
In [12]: obj3.reindex(range(6), method='pad')
Out[12]:
0 blue
1 blue
2 purple
3 purple
4 yellow
5 yellow
dtype: object
對于DataFrame临燃,reindex可以修改(行)索引鳄虱、列诗力,或兩個都修改凰浮。如果僅傳入一個序列,則會重新索引行
In [13]: frame = DataFrame(np.arange(9).reshape((3, 3)), index=['a', 'c', 'd'],columns=['Ohio', 'Texas', 'California'])
In [14]: frame
Out[14]:
Ohio Texas California
a 0 1 2
c 3 4 5
d 6 7 8
In [15]: frame2=frame.reindex(['a', 'b', 'c', 'd'])
In [16]: frame2
Out[16]:
Ohio Texas California
a 0.0 1.0 2.0
b NaN NaN NaN
c 3.0 4.0 5.0
d 6.0 7.0 8.0
使用columns關鍵字即可重新索引列
In [17]: states = ['Texas', 'Utah', 'California']
In [18]: frame.reindex(columns=states)
Out[18]:
Texas Utah California
a 1 NaN 2
c 4 NaN 5
d 7 NaN 8
利用ix的標簽索引功能
In [28]: frame
Out[28]:
Ohio Texas California
a 0 1 2
c 3 4 5
d 6 7 8
In [31]: states = ['Texas', 'Utah', 'California']
In [32]: frame.ix[['a', 'b', 'c', 'd'], states]
Out[32]:
Texas Utah California
a 1.0 NaN 2.0
b NaN NaN NaN
c 4.0 NaN 5.0
d 7.0 NaN 8.0
丟棄某條軸上的一個或多個項很簡單苇本,只要有一個索引數(shù)組或列表即可袜茧。由于需要執(zhí)行一些數(shù)據(jù)整理和集合邏輯,所以drop方法返回的是一個在指定軸上刪除了指定值的新對象
In [33]: obj=Series(np.arange(5.),index=['a', 'b', 'c', 'd', 'e'])
In [34]: obj
Out[34]:
a 0.0
b 1.0
c 2.0
d 3.0
e 4.0
dtype: float64
In [35]: new_obj=obj.drop('c')
In [36]: new_obj
Out[36]:
a 0.0
b 1.0
d 3.0
e 4.0
dtype: float64
In [37]: obj.drop(['d','b'])
Out[37]:
a 0.0
c 2.0
e 4.0
dtype: float64
對于DataFrame圈澈,可以刪除任意軸上的索引值
In [41]: data = DataFrame(np.arange(16).reshape((4, 4)),
...: index=['Ohio', 'Colorado', 'Utah', 'New York'],
...: columns=['one', 'two', 'three', 'four'])
In [42]: data
Out[42]:
one two three four
Ohio 0 1 2 3
Colorado 4 5 6 7
Utah 8 9 10 11
New York 12 13 14 15
In [43]: data.drop(['Colorado', 'Ohio'])
Out[43]:
one two three four
Utah 8 9 10 11
New York 12 13 14 15
In [44]: data.drop('two',axis=1)
Out[44]:
one three four
Ohio 0 2 3
Colorado 4 6 7
Utah 8 10 11
New York 12 14 15
In [45]: data.drop(['two', 'four'], axis=1)
Out[45]:
one three
Ohio 0 2
Colorado 4 6
Utah 8 10
New York 12 14
索引、選取和過濾
Series的索引值不只是整數(shù)
In [47]: obj=Series(np.arange(5.),index=['a', 'b', 'c', 'd','e'])
In [48]: obj
Out[48]:
a 0.0
b 1.0
c 2.0
d 3.0
e 4.0
dtype: float64
In [49]: obj['b']
Out[49]: 1.0
In [50]: obj[3]
Out[50]: 3.0
In [51]: obj[3:5]
Out[51]:
d 3.0
e 4.0
dtype: float64
In [52]: obj[['b','e','d']]
Out[52]:
b 1.0
e 4.0
d 3.0
dtype: float64
In [53]: obj[[1,4]]
Out[53]:
b 1.0
e 4.0
dtype: float64
In [54]: obj[obj<3]
Out[54]:
a 0.0
b 1.0
c 2.0
dtype: float64
利用標簽的切片運算與普通的Python切片運算不同尘惧,其末端是包含的(inclusive)
In [55]: obj['b':'d']
Out[55]:
b 1.0
c 2.0
d 3.0
dtype: float64
In [56]: obj['b':'d']=6
In [57]: obj
Out[57]:
a 0.0
b 6.0
c 6.0
d 6.0
e 4.0
dtype: float64
DataFrame進行索引其實就是獲取一個或多個列
In [60]: data = DataFrame(np.arange(16).reshape((4, 4)),
...: index=['Ohio', 'Colorado', 'Utah', 'New York'],
...: columns=['one', 'two', 'three', 'four'])
In [61]: data
Out[61]:
one two three four
Ohio 0 1 2 3
Colorado 4 5 6 7
Utah 8 9 10 11
New York 12 13 14 15
In [62]: data['two']
Out[62]:
Ohio 1
Colorado 5
Utah 9
New York 13
Name: two, dtype: int32
In [63]: data[['three','one']]
Out[63]:
three one
Ohio 2 0
Colorado 6 4
Utah 10 8
New York 14 12
通過切片或布爾型數(shù)組選取行
In [64]: data[:3]
Out[64]:
one two three four
Ohio 0 1 2 3
Colorado 4 5 6 7
Utah 8 9 10 11
In [65]: data[data['three']>5]
Out[65]:
one two three four
Colorado 4 5 6 7
Utah 8 9 10 11
New York 12 13 14 15
通過布爾型DataFrame(比如下面由標量比較運算得出的)進行索引
In [66]: data<6
Out[66]:
one two three four
Ohio True True True True
Colorado True True False False
Utah False False False False
New York False False False False
In [67]: data[data<5]=0
In [68]: data
Out[68]:
one two three four
Ohio 0 0 0 0
Colorado 0 5 6 7
Utah 8 9 10 11
New York 12 13 14 15
利用索引字段ix,它可以通過NumPy式的標記法以及軸標簽從DataFrame中選取行和列的子集康栈。其中:ix is deprecated,可以使用loc
In [69]: data.ix['Colorado', ['two', 'three']]
C:\ProgramData\Anaconda3\lib\site-packages\ipykernel_launcher.py:1: DeprecationWarning:
.ix is deprecated. Please use
.loc for label based indexing or
.iloc for positional indexing
See the documentation here:
http://pandas.pydata.org/pandas-docs/stable/indexing.html#deprecate_ix
"""Entry point for launching an IPython kernel.
Out[69]:
two 5
three 6
Name: Colorado, dtype: int32
In [70]: data.loc['Colorado', ['two', 'three']]
Out[70]:
two 5
three 6
Name: Colorado, dtype: int32
In [71]: data.ix[['Colorado', 'Utah'], [3, 0, 1]]
Out[71]:
four one two
Colorado 7 0 5
Utah 11 8 9
In [72]: data.ix[2]
Out[72]:
one 8
two 9
three 10
four 11
Name: Utah, dtype: int32
In [73]: data.loc[:'Utah','two']
Out[73]:
Ohio 0
Colorado 5
Utah 9
Name: two, dtype: int32
In [74]: data.ix[data.three>5]
Out[74]:
one two three four
Colorado 0 5 6 7
Utah 8 9 10 11
New York 12 13 14 15
In [75]: data.ix[data.three > 5, :3]
Out[75]:
one two three
Colorado 0 5 6
Utah 8 9 10
New York 12 13 14
對pandas對象中的數(shù)據(jù)的選取和重排方式有很多
為什么不是輸出7 4 5喷橙,而輸出的是7 0 5啥么,是不能理解的小地方,只能慢慢體會其中的用法贰逾。
其中悬荣,get_value方法是選取,set-value方法是設置
算術運算和數(shù)據(jù)對齊
Pandas可以對不同索引的對象進行算術運算疙剑。在將對象相加時氯迂,如果存在不同的索引對,則結果的索引就是該索引對的并集言缤。
In [77]: s1=Series([6.8,-4.5,3.6,5.6],index=['a','c','d','e'])
In [78]: s2 = Series([-6.5, 3.6, -5.6, 4, 3.1], index=['a', 'c', 'e', 'f', 'g'])
In [79]: s1
Out[79]:
a 6.8
c -4.5
d 3.6
e 5.6
dtype: float64
In [80]: s2
Out[80]:
a -6.5
c 3.6
e -5.6
f 4.0
g 3.1
dtype: float64
In [81]: s1+s2
Out[81]:
a 0.3
c -0.9
d NaN
e 0.0
f NaN
g NaN
dtype: float64
自動的數(shù)據(jù)對齊操作在不重疊的索引處引入了NA值嚼蚀。缺失值會在算術運算過程中傳播。對于DataFrame管挟,對齊操作會同時發(fā)生在行和列上轿曙。相加后將會返回一個新的DataFrame,其索引和列為原來那兩個DataFrame的并集
In [85]: df1 = DataFrame(np.arange(9.).reshape((3, 3)), columns=list('bcd'),
...: index=['Ohio', 'Texas', 'Colorado'])
In [86]: df2 = DataFrame(np.arange(12.).reshape((4, 3)), columns=list('bde'),
...: index=['Utah', 'Ohio', 'Texas', 'Oregon'])
In [87]: df1
Out[87]:
b c d
Ohio 0.0 1.0 2.0
Texas 3.0 4.0 5.0
Colorado 6.0 7.0 8.0
In [88]: df2
Out[88]:
b d e
Utah 0.0 1.0 2.0
Ohio 3.0 4.0 5.0
Texas 6.0 7.0 8.0
Oregon 9.0 10.0 11.0
In [89]: df1+df2
Out[89]:
b c d e
Colorado NaN NaN NaN NaN
Ohio 3.0 NaN 6.0 NaN
Oregon NaN NaN NaN NaN
Texas 9.0 NaN 12.0 NaN
Utah NaN NaN NaN NaN
在算術方法中填充值
在對不同索引的對象進行算術運算時僻孝,你可能希望當一個對象中某個軸標簽在另一個對象中找不到時填充一個特殊值(比如0)导帝,相加時,沒有重疊的位置就會產(chǎn)生NA值穿铆。
In [95]: f1 = DataFrame(np.arange(12.).reshape((3, 4)), columns=list('abcd'))
In [96]: f2 = DataFrame(np.arange(20.).reshape((4, 5)), columns=list('abcde'))
In [97]: f1
Out[97]:
a b c d
0 0.0 1.0 2.0 3.0
1 4.0 5.0 6.0 7.0
2 8.0 9.0 10.0 11.0
In [98]: f2
Out[98]:
a b c d e
0 0.0 1.0 2.0 3.0 4.0
1 5.0 6.0 7.0 8.0 9.0
2 10.0 11.0 12.0 13.0 14.0
3 15.0 16.0 17.0 18.0 19.0
In [99]: f1+f2
Out[99]:
a b c d e
0 0.0 2.0 4.0 6.0 NaN
1 9.0 11.0 13.0 15.0 NaN
2 18.0 20.0 22.0 24.0 NaN
3 NaN NaN NaN NaN NaN
使用add方法您单,傳入f2以及一個fill_value參數(shù)
In [102]: f1.add(f2, fill_value=0)
Out[102]:
a b c d e
0 0.0 2.0 4.0 6.0 4.0
1 9.0 11.0 13.0 15.0 9.0
2 18.0 20.0 22.0 24.0 14.0
3 15.0 16.0 17.0 18.0 19.0
在對Series或DataFrame重新索引時,也可以指定一個填充值
In [103]: f1.reindex(columns=f2.columns, fill_value=0)
Out[103]:
a b c d e
0 0.0 1.0 2.0 3.0 0
1 4.0 5.0 6.0 7.0 0
2 8.0 9.0 10.0 11.0 0
In [105]: f1*f2
Out[105]:
a b c d e
0 0.0 1.0 4.0 9.0 NaN
1 20.0 30.0 42.0 56.0 NaN
2 80.0 99.0 120.0 143.0 NaN
3 NaN NaN NaN NaN NaN
DataFrame和Series之間的運算
計算一個二維數(shù)組與其某行之間的差荞雏,出現(xiàn)的結果這就叫做廣播(broadcasting)睹限,如下:
In [106]: arr=np.arange(12.).reshape((3,4))
In [107]: arr
Out[107]:
array([[ 0., 1., 2., 3.],
[ 4., 5., 6., 7.],
[ 8., 9., 10., 11.]])
In [108]: arr[0]
Out[108]: array([ 0., 1., 2., 3.])
In [109]: arr-arr[0]
Out[109]:
array([[ 0., 0., 0., 0.],
[ 4., 4., 4., 4.],
[ 8., 8., 8., 8.]])
默認情況下譬猫,DataFrame和Series之間的算術運算會將Series的索引匹配到DataFrame的列,然后沿著行一直向下廣播
In [110]: frame = DataFrame(np.arange(12.).reshape((4, 3)), columns=list('bde'),
...: index=['Utah', 'Ohio', 'Texas', 'Oregon'])
In [111]: frame
Out[111]:
b d e
Utah 0.0 1.0 2.0
Ohio 3.0 4.0 5.0
Texas 6.0 7.0 8.0
Oregon 9.0 10.0 11.0
In [112]: series = frame.ix[0]
In [113]: series
Out[113]:
b 0.0
d 1.0
e 2.0
Name: Utah, dtype: float64
In [114]: frame-series
Out[114]:
b d e
Utah 0.0 0.0 0.0
Ohio 3.0 3.0 3.0
Texas 6.0 6.0 6.0
Oregon 9.0 9.0 9.0
如果某個索引值在DataFrame的列或Series的索引中找不到羡疗,則參與運算的兩個對象就會被重新索引以形成并集
In [115]: series2 = Series(range(3), index=['b', 'e', 'f'])
In [116]: series2
Out[116]:
b 0
e 1
f 2
dtype: int32
In [117]: frame + series2
Out[117]:
b d e f
Utah 0.0 NaN 3.0 NaN
Ohio 3.0 NaN 6.0 NaN
Texas 6.0 NaN 9.0 NaN
Oregon 9.0 NaN 12.0 NaN
如果你希望匹配行且在列上廣播染服,則必須使用算術運算方法。
In [118]: series3 = frame['d']
In [119]: series3
Out[119]:
Utah 1.0
Ohio 4.0
Texas 7.0
Oregon 10.0
Name: d, dtype: float64
In [120]: frame
Out[120]:
b d e
Utah 0.0 1.0 2.0
Ohio 3.0 4.0 5.0
Texas 6.0 7.0 8.0
Oregon 9.0 10.0 11.0
In [121]: frame.sub(series3, axis=0)
Out[121]:
b d e
Utah -1.0 0.0 1.0
Ohio -1.0 0.0 1.0
Texas -1.0 0.0 1.0
Oregon -1.0 0.0 1.0
傳入的軸號就是希望匹配的軸叨恨。
函數(shù)應用和映射
NumPy的ufuncs(元素級數(shù)組方法)也可用于操作pandas對象
In [122]: frame = DataFrame(np.random.randn(4, 3), columns=list('bde'),
...: index=['Utah', 'Ohio', 'Texas', 'Oregon'])
In [123]: frame
Out[123]:
b d e
Utah -0.976531 -1.511940 -0.018721
Ohio 0.598117 0.047678 -0.058404
Texas 2.469704 0.027215 1.154004
Oregon 1.308615 -1.634739 0.096210
In [124]: np.abs(frame)
Out[124]:
b d e
Utah 0.976531 1.511940 0.018721
Ohio 0.598117 0.047678 0.058404
Texas 2.469704 0.027215 1.154004
Oregon 1.308615 1.634739 0.096210
將函數(shù)應用到由各列或行所形成的一維數(shù)組上柳刮。DataFrame的apply方法即可實現(xiàn)此功能。
In [125]: f = lambda x: x.max() - x.min()
In [126]: frame.apply(f)
Out[126]:
b 3.446234
d 1.682417
e 1.212408
dtype: float64
In [127]: frame.apply(f,axis=1)
Out[127]:
Utah 1.493219
Ohio 0.656521
Texas 2.442489
Oregon 2.943355
dtype: float64
sum和mean方法
In [128]: def f(x):
...: return Series([x.min(), x.max()], index=['min', 'max'])
...:
In [129]: frame.apply(f)
Out[129]:
b d e
min -0.976531 -1.634739 -0.058404
max 2.469704 0.047678 1.154004
得到frame中各個浮點值的格式化字符串痒钝,使用applymap
In [128]: def f(x):
...:
return Series([x.min(), x.max()], index=['min', 'max'])
In [129]: frame.apply(f)
Out[129]:
b d e
min -0.976531 -1.634739 -0.058404
max 2.469704 0.047678 1.154004
In [130]: format = lambda x: '%.2f' % x
In [131]: frame.applymap(format)
Out[131]:
b d e
Utah -0.98 -1.51 -0.02
Ohio 0.60 0.05 -0.06
Texas 2.47 0.03 1.15
Oregon 1.31 -1.63 0.10
Series有一個用于應用元素級函數(shù)的map方法
In [132]: frame['e'].map(format)
Out[132]:
Utah -0.02
Ohio -0.06
Texas 1.15
Oregon 0.10
Name: e, dtype: object
排序和排名
根據(jù)條件對數(shù)據(jù)集排序(sorting)也是一種重要的內置運算秉颗。要對行或列索引進行排序(按字典順序),可使用sort_index方法送矩,它將返回一個已排序的新對象
In [133]: obj = Series(range(4), index=['d', 'a', 'b', 'c'])
In [134]: obj
Out[134]:
d 0
a 1
b 2
c 3
dtype: int32
In [135]: obj.sort_index()
Out[135]:
a 1
b 2
c 3
d 0
dtype: int32
DataFrame蚕甥,則可以根據(jù)任意一個軸上的索引進行排序
In [136]: frame = DataFrame(np.arange(8).reshape((2, 4)), index=['three', 'one'],
...: columns=['d', 'a', 'b', 'c'])
In [137]: frame
Out[137]:
d a b c
three 0 1 2 3
one 4 5 6 7
In [138]: frame.sort_index()
Out[138]:
d a b c
one 4 5 6 7
three 0 1 2 3
In [139]: frame.sort_index(axis=1)
Out[139]:
a b c d
three 1 2 3 0
one 5 6 7 4
數(shù)據(jù)默認是按升序排序的,但也可以降序排序
In [140]: frame.sort_index(axis=1,ascending=False)
Out[140]:
d c b a
three 0 3 2 1
one 4 7 6 5
series通過索引進行排序
In [148]: obj = Series([6, 9, -8, 3])
In [149]: obj.sort_index()
Out[149]:
0 6
1 9
2 -8
3 3
dtype: int64
series通過升值進行排序
In [150]: obj.sort_values()
Out[150]:
2 -8
3 3
0 6
1 9
dtype: int64
在排序時栋荸,任何缺失值默認都會被放到Series的末尾菇怀,其中order不能排序,使用sort_values進行排序
In [151]: obj = Series([4, np.nan, 6, np.nan, -3, 3])
In [152]: obj.order()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-152-4fc888977b98> in <module>()
----> 1 obj.order()
C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\generic.py in __getattr__(self, name)
2968 if name in self._info_axis:
2969 return self[name]
-> 2970 return object.__getattribute__(self, name)
2971
2972 def __setattr__(self, name, value):
AttributeError: 'Series' object has no attribute 'order'
In [153]: obj.sort_values()
Out[153]:
4 -3.0
5 3.0
0 4.0
2 6.0
1 NaN
3 NaN
dtype: float64
希望根據(jù)一個或多個列中的值進行排序晌块,可以將一個或多個列的名字傳遞給by選項
In [154]: frame = DataFrame({'b': [5, 8, -6, 3], 'a': [0, 1, 0, 1]})
In [155]: frame
Out[155]:
a b
0 0 5
1 1 8
2 0 -6
3 1 3
In [156]: frame.sort_index(by='b')
Out[156]:
a b
2 0 -6
3 1 3
0 0 5
1 1 8
In [157]: frame.sort_index(by=['a','b'])
C:\ProgramData\Anaconda3\lib\site-packages\ipykernel_launcher.py:1: FutureWarning: by argument to sort_index is deprecated, pls use .sort_values(by=...)
"""Entry point for launching an IPython kernel.
Out[157]:
a b
2 0 -6
0 0 5
3 1 3
1 1 8
要根據(jù)多個列進行排序爱沟,傳入名稱的列表
In [158]: frame.sort_values(by=['a','b'])
Out[158]:
a b
2 0 -6
0 0 5
3 1 3
1 1 8
排名(ranking)跟排序關系密切,且它會增設一個排名值(從1開始匆背,一直到數(shù)組中有效數(shù)據(jù)的數(shù)量)呼伸。它跟numpy.argsort產(chǎn)生的間接排序索引差不多,只不過它可以根據(jù)某種規(guī)則破壞平級關系钝尸。默認情況下括享,rank是通過“為各組分配一個平均排名”的方式破壞平級關系的:
In [159]: obj = Series([8, -6, 5, 4, 2, 0, 4])
In [160]: obj
Out[160]:
0 8
1 -6
2 5
3 4
4 2
5 0
6 4
dtype: int64
In [161]: obj.rank()
Out[161]:
0 7.0
1 1.0
2 6.0
3 4.5
4 3.0
5 2.0
6 4.5
dtype: float64
可以根據(jù)值在原數(shù)據(jù)中出現(xiàn)的順序給出排名
In [162]: obj.rank(method='first')
Out[162]:
0 7.0
1 1.0
2 6.0
3 4.0
4 3.0
5 2.0
6 5.0
dtype: float64
按降序進行排名
In [163]: obj.rank(ascending=False, method='max')
Out[163]:
0 1.0
1 7.0
2 2.0
3 4.0
4 5.0
5 6.0
6 4.0
dtype: float64
在行或列上計算排名
In [164]: frame = DataFrame({'b': [4.3, 7, -3, 2], 'a': [0, 1, 0, 1],
...: 'c': [-2, 5, 8, -2.5]})
In [165]: frame
Out[165]:
a b c
0 0 4.3 -2.0
1 1 7.0 5.0
2 0 -3.0 8.0
3 1 2.0 -2.5
In [166]: frame.rank(axis=1)
Out[166]:
a b c
0 2.0 3.0 1.0
1 1.0 3.0 2.0
2 2.0 1.0 3.0
3 2.0 3.0 1.0
帶有重復值的軸索引值的Series
In [167]: obj = Series(range(5), index=['a', 'a', 'b', 'b', 'c'])
In [168]: obj
Out[168]:
a 0
a 1
b 2
b 3
c 4
dtype: int32
is_unique屬性可以告訴它的值是否是唯一的
In [169]: obj.index.is_unique
Out[169]: False
對于帶有重復值的索引,數(shù)據(jù)選取的行為將會有些不同珍促。如果某個索引對應多個值奶浦,則返回一個Series;而對應單個值的踢星,則返回一個標量值
In [170]: obj['a']
Out[170]:
a 0
a 1
dtype: int32
In [171]: obj['c']
Out[171]: 4
In [172]: df = DataFrame(np.random.randn(4, 3), index=['a', 'a', 'b', 'b'])
In [173]: df
Out[173]:
0 1 2
a -0.199619 -0.871154 -0.674903
a 1.573516 0.558822 0.511055
b 0.029318 -0.654353 -0.682175
b -0.563794 1.756565 0.105016
In [174]: df.ix['b']
Out[174]:
0 1 2
b 0.029318 -0.654353 -0.682175
b -0.563794 1.756565 0.105016
通過練習認識到有些地方不能很好的理解澳叉,以后學習中慢慢理解各種函數(shù)的使用。