关于python中loc和iloc方法,,pandas以类似字
关于python中loc和iloc方法,,pandas以类似字
pandas以类似字典的方式来获取某一列的值
import pandas as pd
import numpy as np
table = pd.DataFrame(np.zeros((4,2)), index=[‘a‘,‘b‘,‘c‘,‘d‘], columns=[‘left‘, ‘right‘])
print(table)
得到:
如果我们此时需要得到table列的值
例如:table[‘left‘]
即可得到:
如果我们对于行感兴趣,这时候有两种方法,即 iloc 和 loc 方法
loc是指location的意思,iloc中的i是指integer。这两者的区别如下:
locworks on labels in the index.ilocworks on the positions in the index (so it only takes integers)也就是说loc是根据index来索引,
如上table定义了一个index,那么loc就根据这个index来索引对应的行。
iloc是根据行号来索引,行号从0开始,逐次加1。
例如:
print(table.iloc[0])
print(table.loc[‘a‘])
关于python中loc和iloc方法
相关内容
- 选择 Python3.6 还是 Python 3.7,,转自 白月黑羽Pyt
- python中的 upper() 、lower()、capitalize()、title()方法,,upp
- 初学者对Python的认知,, ython是一门
- Python:Base4,,1.python把函
- python可视化---scatter()函数,,函数功能:寻找变量之
- python3.6_单例模式,,单例模式的几种实现方
- python2.*---->python3.5,,环境centos7.
- python中执行js,,import exe
- 【学习总结】Python-3-多个变量赋值,,菜鸟教程-Pytho
- Python----朴素贝叶斯,,1、朴素贝叶斯 朴
评论关闭