pandas选取特定索引的行
来源:互联网 发布:cctv网络直播电视大全 编辑:程序博客网 时间:2024/05/18 22:42
- >>> 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
- >>>
>>> 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) num2 34 56 78 910 11>>> select_index=index[index>5]>>> print(select_index)[ 6 8 10]>>> data['num'].loc[select_index]6 78 910 11Name: num, dtype: int32>>>
注意,不能用iloc,iloc是将序列当作数组来访问,下标又会从0开始:
- >>> 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 78 910 11Name: num, dtype: int32>>> data['num'].iloc[[2,3,4]]6 78 910 11Name: num, dtype: int32>>>
转自博客:
http://blog.csdn.net/o1101574955/article/details/51638128
0 0
- pandas选取特定索引的行
- pandas选取特定索引的行
- pandas索引选取和过滤和ix的各种索引
- python选取特定列——pandas的iloc和loc以及icol使用(列切片及行切片)
- Pandas数据的选取
- pandas中如何索引到某一列的特定值
- 指定选取textarea的特定行
- 指定选取textarea的特定行
- pandas 索引选取和过滤(四)
- pandas学习笔记-索引、选取和过滤
- pandas之索引、选取和过滤
- pandas 选取子集的操作
- pandas随机选取若干行
- 初学pandas(八)条件选取行的便捷…
- python/pandas数据分析(十六)- 数据索引与选取
- Pandas 索引(index)/选取(select)/标签(label)操作
- jQuery 选取具有特定value的option
- 索引关键字的选取原则
- hashMap 实现原理(解释的清晰,转载一下)
- JSP--(一)
- [网易]字符串编码
- 【转】详解ThreadPoolExecutor
- 解决java前后端分离跨域的问题
- pandas选取特定索引的行
- 第5篇:ui-router路由带参数跳转后controller执行两次的问题处理
- java-模拟斗地主的洗牌和发牌
- socket通信基础(二)
- 在Android Studio中创建能调用C/C++函数的APK
- canvas和svg
- 【转】Java线程:新特征-锁(1)
- OBS源码分析--视频采集显示
- 七牛云上传