python,pandas,按条件删除行

标签 python pandas dataframe conditional-statements

你好,我需要帮助根据条件删除一些行:如果估计价格减去价格超过 1500(正),则删除该行

    price      estimated price 
 0  13295                13795
 1  19990                22275
 2   7295                 6498
例如,只有索引 1 会被删除
谢谢你!

最佳答案

如果小于或等于 1500,则更改获取所有行的逻辑减去后 boolean indexing Series.le :

df1 = df[df['estimated price'].sub(df['price']).le(1500)]
像反转掩码一样工作,更像 1500 :
df1 = df[~df['estimated price'].sub(df['price']).gt(1500)]

关于python,pandas,按条件删除行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69388274/

相关文章:

python - 为什么这个多处理代码会失败?

python - 如何将整个网页读入变量

scala - spark DataFrame "as"方法的使用

python - Pandas 比较相似的 DataFrames 并获得 Min

python - key :Value Pairs from txt file into a dictionary

python - 分辨率列表(OpenCv、Python、相机)

pandas - 如何根据 Pandas 的条件进行分组

python - ValueError : all the input array dimensions for the concatenation axis must match exactly, 但沿维度 2,索引 0 处的数组大小为 3

python - pandas 线图导数的绘图变化

python - 从 MultiIndex DataFrame 为切片分配新值