• 技术文章 >常见问题 >Python常见问题

    python中loc是什么

    silencementsilencement2020-01-15 14:38:27原创6560

    loc中的数据是列名,是字符串,所以前后都要取;iloc中数据是int整型,所以是Python默认的前闭后开

    loc函数

    构建数据集df

    import pandas as pd  
    df = pd.DataFrame([  
                ['green', 'M', 10.1, 'class1'],   
                ['red', 'L', 13.5, 'class2'],   
                ['blue', 'XL', 15.3, 'class1']])  
    print (df)    
    # 数据集为以下内容,所有操作均对df进行
           0   1     2       3
    0  green   M  10.1  class1
    1    red   L  13.5  class2
    2   blue  XL  15.3  class1

    loc函数主要通过行标签索引行数据,划重点,标签!标签!标签!
    loc[1] 选择行标签是1的(从0、1、2、3这几个行标签中)

    In[1]:    df.loc[1]
    Out[1]: 0       red
    1         L
    2      13.5
    3    class2

    推荐学习《python教程》。

    专题推荐:python
    品易云
    上一篇:如何三个月学会python 下一篇:pychram找不到python解释器怎么办

    相关文章推荐

    • python如何取出字典的key• idea中怎么写python• python如何打印中文数组• 大学如何学好python

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网