【利用python进行数据分析】学习笔记-第5章 pandas入门——pandas的基本功能

5.2 基本功能

5.2.1 重新索引

In [91]: obj = pd.Series([4.5, 7.2, -5.3, 3.6], index=['d', 'b', 'a', 'c'])
              
In [92]: obj
Out[92]:
d   4.5
b   7.2
a  -5.3
c   3.6
dtype: float64

# ⽤该Series的reindex将会根据新索引进⾏重排
In [93]: obj2 = obj.reindex(['a', 'b', 'c', 'd', 'e'])
In [94]: obj2
Out[94]:
a -5.3
b 7.2
c 3.6
d 4.5
e NaN
dtype: float64
    
# 对于时间序列这样的有序数据,重新索引时可能需要做⼀些插值处理。method选项即可达到此⽬的
In [95]: obj3 = pd.Series(['blue', 'purple', 'yellow'], index=[0, 2, 4])
    
In [96]: obj3
Out[96]:
0    blue
2  purple
4  yellow
dtype: object
    
In [97]: obj3.reindex(range(6), method='ffill') # 使⽤ffill可以实现前向值填充
Out[97]:
0    blue
1    blue
2  purple
3  purple
4  yellow
5  yellow
dtype: object
    
# 借助DataFrame,reindex可以修改(⾏)索引和列
In [98]: frame = pd.DataFrame(np.arange(9).reshape((3, 3)),
   ....:                      index=['a', 'c', 'd'],
   ....:                      columns=['Ohio', 'Texas', 'California'])
    
In [99]: frame
Out[99]:
   Ohio  Texas  California
a     0      1           2
c     3      4           5
d     6      7           8

In [100]: frame2 = frame.reindex(['a', 'b', 'c', 'd'])
    
In [101]: frame2
Out[101]:
   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 [102]: states = ['Texas', 'Utah', 'California']
    
In [103]: frame.reindex(columns=states)
Out[103]:
   Texas  Utah  California
a      1   NaN           2
c      4   NaN           5
d      7   NaN           8
  • reindex函数的参数:

    参数说明
    index用作索引的新序列
    method插值(填充)方式
    fill_value在重新索引的过程中,需要引入缺失值时使用的代替值
    limit前向或后向填充时的最大填充量
    tolerance前向或后向填充时,填充不准确匹配项的最大间距
    level在MultiIndex的指定级别上匹配简单索引,否则选取其子集
    copy默认为True,无论如何都复制

5.2.2 丢弃指定轴上的项

# 丢弃某条轴上的⼀个或多个项只要有⼀个索引数组或列表
In [105]: obj = pd.Series(np.arange(5.), index=['a', 'b', 'c', 'd', 'e'] 

In [106]: obj
Out[106]:
a 0.0
b 1.0
c 2.0
d 3.0
e 4.0
dtype: float64
                          
In [107]: new_obj = obj.drop('c')
                          
In [108]: new_obj
Out[108]:
a 0.0
b 1.0
d 3.0
e 4.0
dtype: float64
                          
In [109]: obj.drop(['d', 'c'])
Out[109]:
a 0.0
b 1.0
e 4.0
dtype: float64
                          
### 对于DataFrame,drop可以删除任意轴上的索引值
In [110]: data = pd.DataFrame(np.arange(16).reshape((4, 4)),
   .....: index=['Ohio', 'Colorado', 'Utah', 'New York'],
   .....: columns=['one', 'two', 'three', 'four']
      
In [111]: data
Out[111]:
          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
                              
# ⽤标签序列调⽤drop会从⾏标签(axis 0)删除值
In [112]: data.drop(['Colorado', 'Ohio'])
Out[112]:
          one  two  three  four
Utah        8    9     10    11
New York   12   13     14    15
                              
# 通过传递axis=1或axis='columns'可以删除列的值
In [113]: data.drop('two', axis=1)
Out[113]:
          one  three  four
Ohio        0      2     3
Colorado    4      6     7
Utah        8     10    11
New York   12     14    15
                              
In [114]: data.drop(['two', 'four'], axis='columns')
Out[114]:
          one  three
Ohio        0      2
Colorado    4      6
Utah        8     10
New York   12     14
                              
# 参数inplace会销毁所有被删除的数据
In [115]: obj.drop('c', inplace=True)
                              
In [116]: obj
Out[116]:
a  0.0
b  1.0
d  3.0
e  4.0
dtype: float64

5.2.3 索引、选取和过滤

# Series索引类似于NumPy数组的索引
In [117]: obj = pd.Series(np.arange(4.), index=['a', 'b', 'c', 'd'])
                                                
In [118]: obj
Out[118]:
a  0.0
b  1.0
c  2.0
d  3.0
dtype: float64
    
In [119]: obj['b']
Out[119]: 1.0
    
In [120]: obj[1]
Out[120]: 1.0
    
In [121]: obj[2:4]
Out[121]:
c   2.0
d   3.0
dtype: float64
    
In [122]: obj[['b', 'a', 'd']]
Out[122]:
b  1.0
a  0.0
d  3.0
dtype: float64
In [123]: obj[[1, 3]]
Out[123]:
b  1.0
d  3.0
dtype: float64
In [124]: obj[obj < 2]
Out[124]:
a  0.0
b  1.0
dtype: float64
    
# 利⽤标签的切⽚运算与普通的Python切⽚运算不同,其末端是包含的
In [125]: obj['b':'c']
Out[125]:
b  1.0
c  2.0
dtype: float64
    
# ⽤切⽚可以对Series的相应部分进⾏设置
In [126]: obj['b':'c'] = 5

In [127]: obj
Out[127]:
a  0.0
b  5.0
c  5.0
d  3.0
dtype: float64
    
# ⽤⼀个值或序列对DataFrame进⾏索引其实就是获取⼀个或多个列
In [128]: data = pd.DataFrame(np.arange(16).reshape((4, 4)),
   .....: index=['Ohio', 'Colorado', 'Utah', 'New York'],
   .....: columns=['one', 'two', 'three', 'four']
                   
In [129]: data
Out[129]:
          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 [130]: data['two']
Out[130]:
Ohio       1
Colorado   5
Utah       9
New York  13
Name: two, dtype: int64
                              
In [131]: data[['three', 'one']]
Out[131]:
          three  one
Ohio          2    0
Colorado      6    4
Utah         10    8
New York     14   12
                              
# 通过切⽚或布尔型数组选取数据
In [132]: data[:2]
Out[132]:
          one  two  three  four
Ohio        0    1      2     3
Colorado    4    5      6     7
                              
In [133]: data[data['three'] > 5]
Out[133]:
          one  two  three  four
Colorado    4    5      6     7
Utah        8    9     10    11
New York   12   13     14    15
                              
# 是通过布尔型DataFrame进⾏索引
In [134]: data < 5
Out[134]:
            one    two  three   four
Ohio       True   True   True   True
Colorado   True  False  False  False
Utah      False  False  False  False
New York  False  False  False  False
                              
In [135]: data[data < 5] = 0
                              
In [136]: data
Out[136]:
          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

5.2.4 用loc和iloc进行选取

# loc和iloc类似NumPy的标记,使⽤轴标签(loc)或整数索引(iloc),从DataFrame选择⾏和列的⼦集
In [137]: data.loc['Colorado', ['two', 'three']]
Out[137]:
two   5
three 6
Name: Colorado, dtype: int64
        
# ⽤iloc和整数进⾏选取
In [138]: data.iloc[2, [3, 0, 1]]
Out[138]:
four  11
one    8
two    9
Name: Utah, dtype: int64
        
In [139]: data.iloc[2]
Out[139]:
one     8
two     9
three  10
four   11
Name: Utah, dtype: int64
        
In [140]: data.iloc[[1, 2], [3, 0, 1]]
Out[140]:
          four  one  two
Colorado     7    0    5
Utah        11    8    9

# 这两个索引函数也适⽤于⼀个标签或多个标签的切⽚
In [141]: data.loc[:'Utah', 'two']
Out[141]:
Ohio      0
Colorado  5
Utah      9
Name: two, dtype: int64
        
In [142]: data.iloc[:, :3][data.three > 5]
Out[142]:
          one  two  three
Colorado    0    5      6
Utah        8    9     10
New York   12   13     14

5.2.5 整数索引

# pandas可以勉强进⾏整数索引,但是会导致⼩bug
In [144]: ser
Out[144]:
0  0.0
1  1.0
2  2.0
dtype: float64
    
In [145]: ser2 = pd.Series(np.arange(3.), index=['a', 'b', 'c'])
    
In [146]: ser2[-1]
Out[146]: 2.0
    
# 如果轴索引含有整数,数据选取总会使⽤标签。为了更准确,请使⽤loc(标签)或iloc(整数)
In [147]: ser[:1]
Out[147]:
0  0.0
dtype: float64
    
In [148]: ser.loc[:1]
Out[148]:
0  0.0
1  1.0
dtype: float64
    
In [149]: ser.iloc[:1]
Out[149]:
0  0.0
dtype: float64

5.2.6 算术运算和数据对齐

# 在将对象相加时,如果存在不同的索引对,则结果的索引就是该索引对的并集
In [150]: s1 = pd.Series([7.3, -2.5, 3.4, 1.5], index=['a', 'c', 'd', 'e'])

In [151]: s2 = pd.Series([-2.1, 3.6, -1.5, 4, 3.1],
   .....:                index=['a', 'c', 'e', 'f', 'g'])
   
In [152]: s1
Out[152]:
a   7.3
c  -2.5
d   3.4
e   1.5
dtype: float64

In [153]: s2
Out[153]:
a -2.1
c 3.6
e -1.5
f 4.0
g 3.1
dtype: float64

In [154]: s1 + s2
Out[154]:
a  5.2
c  1.1
d  NaN
e  0.0
f  NaN
g  NaN
dtype: float64

# 对于DataFrame,对⻬操作会同时发⽣在⾏和列上
In [155]: df1 = pd.DataFrame(np.arange(9.).reshape((3, 3)),
                             columns=['b', 'c', 'd']
   .....:                    index=['Ohio', 'Texas', 'Colorado'])
    
In [156]: df2 = pd.DataFrame(np.arange(12.).reshape((4, 3)),
                             columns=['b', 'd', 'e']
   .....:                    index=['Utah', 'Ohio', 'Texas', 'Oregon'])
                              
In [157]: df1
Out[157]:
            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 [158]: df2
Out[158]:
          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 [159]: df1 + df2
Out[159]:
            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

# 如果DataFrame对象相加,没有共⽤的列或⾏标签,结果都会是空
In [160]: df1 = pd.DataFrame({'A': [1, 2]})
    
In [161]: df2 = pd.DataFrame({'B': [3, 4]})
    
In [162]: df1
Out[162]:
   A
0  1
1  2

In [163]: df2
Out[163]:
   B
0  3
1  4

In [164]: df1 - df2
Out[164]:
     A    B
0  NaN  NaN
1  NaN  NaN

5.2.7 在算术方法中填充值

# 在对不同索引的对象进⾏算术运算时,你可能希望当⼀个对象中某个轴标签在另⼀个对象中找不到时填充⼀个特殊值
In [165]: df1 = pd.DataFrame(np.arange(12.).reshape((3, 4)),
   .....:                    columns=list('abcd'))
   
In [166]: df2 = pd.DataFrame(np.arange(20.).reshape((4, 5)),
   .....:                    columns=list('abcde'))
   
In [167]: df2.loc[1, 'b'] = np.nan

In [168]: df1
Out[168]:
     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 [169]: df2
Out[169]:
      a     b     c     d     e
0   0.0   1.0   2.0   3.0   4.0
1   5.0   NaN   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

# 将它们相加时,没有重叠的位置就会产⽣NA值
In [170]: df1 + df2
Out[170]:
      a     b     c     d    e
0   0.0   2.0   4.0   6.0  NaN
1   9.0   NaN  13.0  15.0  NaN
2  18.0  20.0  22.0  24.0  NaN
3   NaN   NaN   NaN   NaN  NaN

# 使⽤df1的add⽅法,传⼊df2以及⼀个fill_value参数
In [171]: df1.add(df2, fill_value=0)
Out[171]:
      a     b     c     d     e
0   0.0   2.0   4.0   6.0   4.0
1   9.0   5.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

In [172]: 1 / df1
Out[172]:
          a         b         c         d
0       inf  1.000000  0.500000  0.333333
1  0.250000  0.200000  0.166667  0.142857
2  0.125000  0.111111  0.100000  0.090909

In [173]: df1.rdiv(1)
Out[173]:
          a         b         c         d
0       inf  1.000000  0.500000  0.333333
1  0.250000  0.200000  0.166667  0.142857
2  0.125000  0.111111  0.100000  0.090909

# 与此类似,在对Series或DataFrame重新索引时,也可以指定⼀个填充值
In [174]: df1.reindex(columns=df2.columns, fill_value=0)
Out[174]:
     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
  • Series和DataFrame的算术⽅法

    方法说明
    add, radd+
    sub, rsub-
    div, rdiv/
    floordiv, rfloordiva//
    mul, rmul*
    pow, rpow**

5.2.8 DataFrame和Series之间的运算

# 当我们从arr减去arr[0],每⼀⾏都会执⾏这个操作。这就叫做⼴播
In [175]: arr = np.arange(12.).reshape((3, 4))
In [176]: arr
Out[176]:
array([[ 0.,  1.,   2.,   3.],
       [ 4.,  5.,   6.,   7.],
       [ 8.,  9.,  10.,  11.]])
       
In [177]: arr[0]
Out[177]: array([ 0., 1., 2., 3.])

In [178]: arr - arr[0]
Out[178]:
array([[ 0., 0., 0., 0.],
       [ 4., 4., 4., 4.],
       [ 8., 8., 8., 8.]])

In [179]: frame = pd.DataFrame(np.arange(12.).reshape((4, 3)),
   .....:                      columns=list('bde'),
   .....:                      index=['Utah', 'Ohio', 'Texas', 
 
In [180]: series = frame.iloc[0]
                                      
In [181]: frame
Out[181]:
          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 [182]: series
Out[182]:
b  0.0
d  1.0
e  2.0
Name: Utah, dtype: float64
                                      
# 默认情况下,DataFrame和Series之间的算术运算会将Series的索引匹配到DataFrame的列,然后沿着⾏⼀直向下⼴播
In [183]: frame - series
Out[183]:
          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 [184]: series2 = pd.Series(range(3), index=['b', 'e', 'f'])
In [185]: frame + series2
Out[185]:
          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 [186]: series3 = frame['d']
                                      
In [187]: frame
Out[187]:
          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 [188]: series3
Out[188]:
Utah     1.0
Ohio     4.0
Texas    7.0
Oregon  10.0
Name: d, dtype: float64
                                      
In [189]: frame.sub(series3, axis='index')
Out[189]:
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

5.2.9 函数应用和映射

# NumPy的ufuncs(元素级数组⽅法)也可⽤于操作pandas对象
In [190]: frame = pd.DataFrame(np.random.randn(4, 3), 
   .....:                      columns=['b', 'd', 'e'],
   .....:                      index=['Utah', 'Ohio', 'Texas', 'Oregon'])
                 
In [191]: frame
Out[191]:
                b         d          e
Utah    -0.204708  0.478943  -0.519439
Ohio    -0.555730  1.965781   1.393406
Texas    0.092908  0.281746   0.769023
Oregon   1.246435  1.007189  -1.296221

In [192]: np.abs(frame)
Out[192]:
               b         d         e
Utah    0.204708  0.478943  0.519439
Ohio    0.555730  1.965781  1.393406
Texas   0.092908  0.281746  0.769023
Oregon  1.246435  1.007189  1.296221

# apply⽅法可以将函数应⽤到由各列或⾏所形成的⼀维数组上
In [193]: f = lambda x: x.max() - x.min() # 这⾥的函数f,计算了⼀个Series的最⼤和最⼩的差,在frane的每列都执⾏了⼀次。结果是⼀个Series,使⽤frame的列作为索引。
    
In [194]: frame.apply(f)
Out[194]:
b  1.802165
d  1.684034
e  2.689627
dtype: float64
    
# 如果传递axis='columns'到apply,这个函数会在每⾏执⾏
In [195]: frame.apply(f, axis='columns')
Out[195]:
Utah    0.998382
Ohio    2.521511
Texas   0.676115
Oregon  2.542656
dtype: float64
    
# 许多最为常⻅的数组统计功能都被实现成DataFrame的⽅法(如sum和mean),因此⽆需使⽤apply⽅法
In [196]: def f(x):
   .....:     return pd.Series([x.min(), x.max()], index=['min', 'max'])

In [197]: frame.apply(f)
Out[197]:
             b         d          e
min  -0.555730  0.281746  -1.296221
max   1.246435  1.965781   1.393406

# 元素级的Python函数也是可以⽤的。假如你想得到frame中各个浮点值的格式化字符串,使⽤applymap即可
In [198]: format = lambda x: '%.2f' % x
    
In [199]: frame.applymap(format)
Out[199]:
            b     d      e
Utah    -0.20  0.48  -0.52
Ohio    -0.56  1.97   1.39
Texas    0.09  0.28   0.77
Oregon   1.25  1.01  -1.30

# map方法
In [200]: frame['e'].map(format)
Out[200]:
Utah    -0.52
Ohio     1.39
Texas    0.77
Oregon  -1.30
Name: e, dtype: object

5.2.10 排序和排名

# 根据条件对数据集排序(sorting)也是⼀种重要的内置运算。要对⾏或列索引进⾏排序(按字典顺序),可使⽤sort_index⽅法,它将返回⼀个已排序的新对象
In [201]: obj = pd.Series(range(4), index=['d', 'a', 'b', 'c'])
    
In [202]: obj.sort_index()
Out[202]:
a  1
b  2
c  3
d  0
dtype: int64
    
# 对于DataFrame,则可以根据任意⼀个轴上的索引进⾏排序
In [203]: frame = pd.DataFrame(np.arange(8).reshape((2, 4)),
   .....:                      index=['three', 'one'],
   .....:                      columns=['d', 'a', 'b', 'c'])
    
In [204]: frame.sort_index()
Out[204]:
       d  a  b  c
one    4  5  6  7
three  0  1  2  3

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

# 数据默认是按升序排序的,但也可以降序排序
In [206]: frame.sort_index(axis=1, ascending=False)
Out[206]:
       d  c  b  a
three  0  3  2  1
one    4  7  6  5

# 若要按值对Series进⾏排序,可使⽤其sort_values⽅法
In [207]: obj = pd.Series([4, 7, -3, 2])
    
In [208]: obj.sort_values()
Out[208]:
2  -3
3   2
0   4
1   7
dtype: int64
    
# 在排序时,任何缺失值默认都会被放到Series的末尾
In [209]: obj = pd.Series([4, np.nan, 7, np.nan, -3, 2])
    
In [210]: obj.sort_values()
Out[210]:
4  -3.0
5   2.0
0   4.0
2   7.0
1   NaN
3   NaN
dtype: float64
    
# 将⼀个或多个列的名字传递给sort_values的by选项即可根据⼀个或多个列中的值进⾏排序
In [211]: frame = pd.DataFrame({'b': [4, 7, -3, 2], 'a': [0, 1, 0, 1]})

In [212]: frame
Out[212]:
   a   b
0  0   4
1  1   7
2  0  -3
3  1   2
                                                          
In [213]: frame.sort_values(by='b')
Out[213]:
   a   b
2  0  -3
3  1   2
0  0   4
1  1   7

# 要根据多个列进⾏排序,传⼊名称的列表即可
In [214]: frame.sort_values(by=['a', 'b'])
Out[214]:
   a   b
2  0  -3
0  0   4
3  1   2
1  1   7

# rank是通过“为各组分配⼀个平均排名”的⽅式破坏平级关系的
In [215]: obj = pd.Series([7, -5, 7, 4, 2, 0, 4])
In [216]: obj.rank()
Out[216]:
0  6.5
1  1.0
2  6.5
3  4.5
4  3.0
5  2.0
6  4.5
dtype: float64
    
# 也可以根据值在原数据中出现的顺序给出排名
In [217]: obj.rank(method='first')
Out[217]:
0  6.0
1  1.0
2  7.0
3  4.0
4  3.0
5  2.0
6  5.0
dtype: float64
    
# 也可以按降序进⾏排名
In [218]: obj.rank(ascending=False, method='max')
Out[218]:
0  2.0
1  7.0
2  2.0
3  4.0
4  5.0
5  6.0
6  4.0
dtype: float64
    
# DataFrame可以在⾏或列上计算排名
In [219]: frame = pd.DataFrame({'b': [4.3, 7, -3, 2], 
   .....:                       'a': [0, 1, 0, 1],
   .....:                       'c': [-2, 5, 8, -2.5]})
                                      
In [220]: frame
Out[220]:
   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 [221]: frame.rank(axis='columns')
Out[221]:
     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

5.2.11 带有重复标签的轴索引

In [222]: obj = pd.Series(range(5), index=['a', 'a', 'b', 'b', 'c'])

In [223]: obj
Out[223]:
a  0
a  1
b  2
b  3
c  4
dtype: int64

# 索引的is_unique属性可以告诉你它的值是否是唯⼀的
In [224]: obj.index.is_unique
Out[224]: False
    
# 如果某个索引对应多个值,则返回⼀个Series;⽽对应单个值的,则返回⼀个标量值
In [225]: obj['a']
Out[225]:
a  0
a  1
dtype: int64
    
In [226]: obj['c']
Out[226]: 4
    
# 对DataFrame的⾏进⾏索引时也是如此
In [227]: df = pd.DataFrame(np.random.randn(4, 3), index=['a', 'a', 'b', 'b'])
                                                          
In [228]: df
Out[228]:
          0          1          2
a  0.274992   0.228913   1.352917
a  0.886429  -2.001637  -0.371843
b  1.669025  -0.438570  -0.539741
b  0.476985   3.248944  -1.021228

In [229]: df.loc['b']
Out[229]:
          0          1          2
b  1.669025  -0.438570  -0.539741
b  0.476985   3.248944  -1.021228
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

From Star.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值