我有一个pandas.DataFrame
,我在上面迭代行。在每一行中,我需要过滤掉一些不值钱的值,并保持索引关联。这就是我现在的处境:
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)
我怎么能做到呢?在
迭代行通常是不好的做法(而且非常慢)。正如@JohnE建议您使用applymap。在
如果我理解你的问题,我想你想做的是:
IRC的一个家伙给了我答案。这里是:
。。。也可以缩短为。。。在
^{pr2}$。。。当然,为了避免再走一步。。。在
相关问题 更多 >
编程相关推荐