pandas选取特定索引的行
2017-05-11 10:42
344 查看
[python] view plain copy print?
>>> import numpy as np
>>> import pandas as pd
>>> index=np.array([2,4,6,8,10])
>>> data=np.array([3,5,7,9,11])
>>> data=pd.DataFrame({’num’:data},index=index)
>>> print(data)
num
2 3
4 5
6 7
8 9
10 11
>>> select_index=index[index>5]
>>> print(select_index)
[ 6 8 10]
>>> data[’num’].loc[select_index]
6<
4000
/span> 7
8 9
10 11
Name: num, dtype: int32
>>>
注意,不能用iloc,iloc是将序列当作数组来访问,下标又会从0开始:
[python] view plain copy print?
>>> data[‘num’].iloc[2:5]
6 7
8 9
10 11
Name: num, dtype: int32
>>> data[’num’].iloc[[2,3,4]]
6 7
8 9
10 11
Name: num, dtype: int32
>>>
转自博客:
http://blog.csdn.net/o1101574955/article/details/51638128
>>> import numpy as np
>>> import pandas as pd
>>> index=np.array([2,4,6,8,10])
>>> data=np.array([3,5,7,9,11])
>>> data=pd.DataFrame({’num’:data},index=index)
>>> print(data)
num
2 3
4 5
6 7
8 9
10 11
>>> select_index=index[index>5]
>>> print(select_index)
[ 6 8 10]
>>> data[’num’].loc[select_index]
6<
4000
/span> 7
8 9
10 11
Name: num, dtype: int32
>>>
>>> import numpy as np >>> import pandas as pd >>> index=np.array([2,4,6,8,10]) >>> data=np.array([3,5,7,9,11]) >>> data=pd.DataFrame({'num':data},index=index) >>> print(data) num 2 3 4 5 6 7 8 9 10 11 >>> select_index=index[index>5] >>> print(select_index) [ 6 8 10] >>> data['num'].loc[select_index] 6 7 8 9 10 11 Name: num, dtype: int32 >>>
注意,不能用iloc,iloc是将序列当作数组来访问,下标又会从0开始:
[python] view plain copy print?
>>> data[‘num’].iloc[2:5]
6 7
8 9
10 11
Name: num, dtype: int32
>>> data[’num’].iloc[[2,3,4]]
6 7
8 9
10 11
Name: num, dtype: int32
>>>
>>> data['num'].iloc[2:5] 6 7 8 9 10 11 Name: num, dtype: int32 >>> data['num'].iloc[[2,3,4]] 6 7 8 9 10 11 Name: num, dtype: int32 >>>
转自博客:
http://blog.csdn.net/o1101574955/article/details/51638128
相关文章推荐
- pandas实现选取特定索引的行
- pandas选取特定索引的行
- python选取特定列——pandas的iloc和loc以及icol使用(列切片及行切片)
- 4000 Pandas 索引(index)/选取(select)/标签(label)操作
- pandas学习笔记-索引、选取和过滤
- pandas 索引选取和过滤(四)
- pandas.DataFrame选取/排除特定行的方法
- pandas 数据索引与选取
- python科学计算笔记(四)pandas 数据索引与选取
- pandas数据清洗,排序,索引设置,数据选取方法
- pandas之索引、选取和过滤
- pandas.DataFrame选取/排除特定行
- python/pandas数据分析(十六)- 数据索引与选取
- pandas索引选取和过滤和ix的各种索引
- pandas数据清洗,排序,索引设置,数据选取
- pandas中如何索引到某一列的特定值
- pandas.DataFrame删除/选取含有特定数值的行或列实例
- pandas数据清洗,排序,索引设置,数据选取
- python pandas 如何找到NaN、缺失值或者某些元素的索引名称以及位置,np.where的使用
- 索引关键字的选取原则