Skip to main content
There no reason to use such large images. Images are best for the output of plots, not data; df[df["cost"].lt(200)].to_clipboard(sep='\\s+', index=True). As per https://stackoverflow.com/help/behavior, do not use signature, taglines, greetings, thanks, or other chitchat.
Source Link
Trenton McKinney
  • 63.2k
  • 41
  • 169
  • 212

I am wondering why no one mentions the builtin functionsHere are options using pandas dataframe has isbuilt-in functions, similar to isin method. Here is a quick example

 df = pd.DataFrame({'cost': [250, 150, 100], 'revenue': [100, 250, 300]},index=['A', 'B', 'C']) cost revenue A 250 100 B 150 250 C 100 300 

Compare DataFrames for equality elementwise

 df=df[df["cost"]df[df["cost"].eq(250)] cost revenue A 250 100 

enter image description here

Compare DataFrames for greater than inequality or equality elementwise.

df=df[df["cost"]df[df["cost"].ge(100)]    cost revenue A 250 100 B 150 250 C 100 300 

enter image description here

Compare DataFrames for strictly less than inequality elementwise.

df =df[df["cost"]df[df["cost"].lt(200)]    cost revenue B 150 250 C 100 300 

enter image description here

I am wondering why no one mentions the builtin functions pandas dataframe has is similar to isin method. Here is a quick example

 df = pd.DataFrame({'cost': [250, 150, 100], 'revenue': [100, 250, 300]},index=['A', 'B', 'C']) cost revenue A 250 100 B 150 250 C 100 300 

Compare DataFrames for equality elementwise

 df=df[df["cost"].eq(250)] 

enter image description here

Compare DataFrames for greater than inequality or equality elementwise.

df=df[df["cost"].ge(100)] 

enter image description here

Compare DataFrames for strictly less than inequality elementwise.

df =df[df["cost"].lt(200)] 

enter image description here

Here are options using pandas built-in functions, similar to isin.

 df = pd.DataFrame({'cost': [250, 150, 100], 'revenue': [100, 250, 300]},index=['A', 'B', 'C']) cost revenue A 250 100 B 150 250 C 100 300 

Compare DataFrames for equality elementwise

 df[df["cost"].eq(250)] cost revenue A 250 100 

Compare DataFrames for greater than inequality or equality elementwise.

df[df["cost"].ge(100)]    cost revenue A 250 100 B 150 250 C 100 300 

Compare DataFrames for strictly less than inequality elementwise.

df[df["cost"].lt(200)]    cost revenue B 150 250 C 100 300 
Source Link

I am wondering why no one mentions the builtin functions pandas dataframe has is similar to isin method. Here is a quick example

 df = pd.DataFrame({'cost': [250, 150, 100], 'revenue': [100, 250, 300]},index=['A', 'B', 'C']) cost revenue A 250 100 B 150 250 C 100 300 

Compare DataFrames for equality elementwise

 df=df[df["cost"].eq(250)] 

enter image description here

Compare DataFrames for greater than inequality or equality elementwise.

df=df[df["cost"].ge(100)] 

enter image description here

Compare DataFrames for strictly less than inequality elementwise.

df =df[df["cost"].lt(200)] 

enter image description here