Reg*_*s01 4 python conditional-statements dataframe pandas
您好,我需要帮助根据条件删除一些行:如果估计价格减去价格超过 1500(正)则删除该行
price estimated price
0 13295 13795
1 19990 22275
2 7295 6498
Run Code Online (Sandbox Code Playgroud)
例如,只有索引 1 会被删除,谢谢!
您可以使用pd.drop()其中可以按索引删除特定行的方法。:
>>> df.drop(df[(df['estimated price']-df['price'] >= 1500)].index)
price estimated price
0 13295 13795
2 7295 6498
Run Code Online (Sandbox Code Playgroud)
index1 被丢弃。
请注意,此方法假设您的信息index是唯一的。如果不是的话,boolean indexing是更好的解决方案。