pandas.dataframe按行索引表达式选取方法

需要把一个从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]]

各位大神有没有更好的办法?望不吝赐教。

以上这篇pandas.dataframe按行索引表达式选取方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

你可能感兴趣的:(pandas.dataframe按行索引表达式选取方法)