• DataFrame的基本操作


    DataFrame的基本操作

    1,选择

    image

    image

    (1),Select column

    In [11]: df['a']
    Out[11]:
    0   -1.355263
    1    0.010888
    2    1.599583
    3    0.004565
    4    0.460270
    Name: a, dtype: float64
    (2),Select row by label
    In [15]: df.loc[1]
    Out[15]:
    a    0.010888
    b   -0.900427
    c   -0.397198
    Name: 1, dtype: float64

    (3) Select row by integer location

    In [19]: df.iloc[1]
    Out[19]:
    a    0.010888
    b   -0.900427
    c   -0.397198
    Name: 1, dtype: float64
    (4) Slice rows
    In [24]: df[1:3]
    Out[24]:
              a         b         c
    1  0.010888 -0.900427 -0.397198
    2  1.599583  0.662713  0.943103

    (5) Select rows by boolean vector

    In [27]: df[df['a']>0.5]
    Out[27]:
              a         b         c
    2  1.599583  0.662713  0.943103

    2,删除

    In [28]: del df['a']
    
    In [29]: df
    Out[29]:
              b         c
    0  1.451534 -0.497793
    1 -0.900427 -0.397198
    2  0.662713  0.943103
    3 -0.505622  1.156941
    4  0.333584 -1.260798
    In [32]: df.pop('b')
    Out[32]:
    0    1.451534
    1   -0.900427
    2    0.662713
    3   -0.505622
    4    0.333584
    Name: b, dtype: float64
    
    In [33]: df
    Out[33]:
              c
    0 -0.497793
    1 -0.397198
    2  0.943103
    3  1.156941
    4 -1.260798
    3,插入
    In [35]: df['e']=['e','w','t','e','d']
    
    In [36]: df
    Out[36]:
              c  e
    0 -0.497793  e
    1 -0.397198  w
    2  0.943103  t
    3  1.156941  e
    4 -1.260798  d
  • 相关阅读:
    mfc判断当前程序是否正在运行
    mfc通过信号量保证线程同步
    delete和析构函数
    获取当前运行的exe路径
    mfc移动文件夹
    Cmake实现样例
    安装Node.js以及Hexo
    分类与回归的关系和区别
    從文本到視覺:各領域最前沿的論文集合
    ubuntu 终端$换行
  • 原文地址:https://www.cnblogs.com/sklww/p/3813006.html
Copyright © 2020-2023  润新知