我有一个 pandas.DataFrame
,我现在就在这里'm iterating over the rows. On each row I need to filter out some non valuable values and keep the indexes association. This is where I':
for i,row in df.iterrows():
my_values = row["first_interesting_column":]
# here I need to filter 'my_values' Series based on a function
# what I'm doin right now is use the built-in python filter function, but what I get back is a list with no indexes anymore
my_valuable_values = filter(lambda x: x != "-", my_values)
我怎样才能做到这一点?
2 回答
我被IRC上的一个人建议了答案 . 这里是:
......也可以缩短......
......当然,要避免再迈一步......
迭代行通常是不好的做法(并且非常慢) . 正如@JohnE建议你想使用applymap .
如果我理解你的问题,我想你想做的是: