if in df columns

Solutions on MaxInterview for if in df columns by the best coders in the world

showing results for - "if in df columns"
Jensen
27 Jul 2018
1if 'A' in df.columns:
Nico
24 May 2019
1if 'A' in df:
Carla
19 May 2019
1import pandas as pd
2
3numbers = {'set_of_numbers': [1,2,3,4,5,6,7,8,9,10]}
4df = pd.DataFrame(numbers,columns=['set_of_numbers'])
5
6df['equal_or_lower_than_4?'] = df['set_of_numbers'].apply(lambda x: 'True' if x <= 4 else 'False')
7
8print (df)
9
similar questions
queries leading to this page
if in df columns