To check if one or more columns exist, you can use set.issubset , for example:
if set(['A','C']).issubset(df.columns): df['sum'] = df['A'] + df['C']
As @brianpck points out in a comment, set([]) can alternatively be constructed using curly braces,
if {'A', 'C'}.issubset(df.columns):
See this question for a discussion of the braces syntax.
Or you can use list comprehension, as in:
if all([item in df.columns for item in ['A','C']]):
C8H10N4O2 07 Sept. '16 at 13:55 on 2016-09-07 13:55
source share