python中pandas里面的dataframe数据的筛选小结
pandas大家用的都很多,像我这种用的不够熟练,也不够多的就只能做做笔记,尽量留下点东西吧。
筛选行:
a. 按照列的条件筛选
df = pandas.DataFrame(...) # supposing it has 3 columns: a, b and c
df[(df['a'] > 0) & (df['b'] < 0) | df['c'] > 0]
b. 按照索引的条件筛选
needed_seq=[1,2,3,6]
needed_df = df.loc[needed_seq]
筛选列:
a. 筛选多列
dfs = df[['a','b']]