pandas.dataframe按行索引表达式选取方法
时间:2021-09-16 09:55:15|栏目:Python代码|点击: 次
需要把一个从csv文件里读取来的数据集等距抽样分割,这里用到了列表表达式和dataframe.iloc
先生成索引列表:
index_list = ['%d' %i for i in range(df.shape[0]) if i % 3 == 0]
在dataframe中选取
sample_df = df.iloc[index_list]
合起来
sample_df = df.iloc[['%d' %i for i in range(df.shape[0]) if i % 3 == 0]]
各位大神有没有更好的办法?望不吝赐教。
上一篇:Python3利用scapy局域网实现自动多线程arp扫描功能
栏 目:Python代码
本文标题:pandas.dataframe按行索引表达式选取方法
本文地址:http://www.codeinn.net/misctech/175512.html






