I'm new to Python. I have a dataframe, and I want to filter it for the times values on Column A have come within 2% range of values on Column B.
So something like (i guess):
df_[df_['B']*0.98<=df_['A']<=df_['B']*1.02]
#this prints an error
len(df_[df_['B']*0.98<=df_['A']<=df_['B']*1.02])
#this prints an error
CodePudding user response:
You need to write conditions separately, put them each in brackets and combine with the &
operator. Try
df = df[(df['B'] <= df['A']*1.02) & (df['A'] <= df['B']*1.02)]
CodePudding user response:
to create a columns in you data frame 'condition_verification'
import numpy as np
df('condition_verification')=np.where((df['B'] <= df['A']*1.02)& (df['A'] <= df['B']*1.02), True, False)