按行和列过滤子集 Pandas 数据框

Filter Subset Pandas Dataframe by rows and columns

我有以下数据框:

import pandas as pd
import numpy as np

df = pd.DataFrame(np.array(([1,2,3], [1,2,3], [1,2,3], [4,5,6])), 
                  columns=['one','two','three'])

#BelowI am sub setting by rows and columns. But I want to have more than just one column. 
#In this case Column 'One' and 'two'
small=df[df.one==1].one

这里有什么选择?

您可以使用 loc:

df = pd.DataFrame(np.array(([1,2,3], [1,2,3], [1,2,3], [4,5,6])), 
              columns=['one','two','three'])

small=df.loc[df.one==1, ["one", "two"]]
# >    one two
#    0  1   2
#    1  1   2
#    2  1   2

loc 的第一个元素是需要的行;第二个是想要的列。如此处所示,它允许屏蔽和索引。