【发布时间】:2016-07-17 04:31:48
【问题描述】:
我正在使用 DataFrame.iterrows() 遍历我的 DataFrame 中的行,如果一行满足某些条件,我将其存储在另一个 DataFrame 中。有没有办法像 set.difference(another_set) 一样删除同时出现的行?
我被要求提供代码,因此,由于我不知道我的问题的答案,我解决了我的问题并创建了另一个 DataFrame,我保存了良好的数据而不是拥有两个 DataFrame 并对其进行区分两者都有。
def test_right_chain(self, temp):
temp__=pd.DataFrame()
temp_=pd.DataFrame()
key=temp["nr right"].iloc[0]
temp_=temp_.append(temp.iloc[0])
temp=temp[1:]
for index, row in temp.iterrows():
print row
key_=row['nr right']
if abs(key_-key)==1:
pass
elif len(temp_)>2:
print row
temp__.append(temp_)
temp_=pd.DataFrame()
else:
temp_=pd.DataFrame()
temp_=temp_.append(row)
key=key_
return temp__
【问题讨论】:
-
您应该至少发布一些输入代码和预期输出,以便我们重现您的问题并为您提供帮助。
-
如果您能以 text 形式提供一个包含 5-7 行的示例输入数据集并提供预期输出,这将更容易为您提供帮助