如何过滤 python 系列的值

How to filter values on a python series

我有一个数据框,我将这个数据框的第一行保存如下

first_row = data_model.loc[0,:]

如果我打印出 first_row,它看起来像

label                class
wa                     3
not                    0
im                     2
time                   0
see                    2
like                   0
going                  2
amp                    1
get                    1
one                    0

我只想保持大于 0 的值,所以我使用 first_row[first_row > 0],但我收到如下错误消息:

TypeError: '>' not supported between instances of 'str' and 'int'.

如果我使用first_row[first_row != 0],我会得到我想要的。

使用DataFrame的查询功能会return得到想要的结果

df=pd.DataFrame({"label:["wa","not","im","time","see","lke","going"],"amp":`[3,0,2,0,2,0,2]})

df=df.query("amp>0")

print(df)

           amp  label
        0    3     wa
        2    2     im
        4    2    see
        6    2  going