I am new to using pandas and writing a script where I read in a data framework and then do some calculations on some columns.
Sometimes I will have a βMetβ column:
df = pd.read_csv(File, sep='\t', compression='gzip', header=0, names=["Chrom", "Site", "coverage", "Met"])
In other cases, I will have:
df = pd.read_csv(File, sep='\t', compression='gzip', header=0, names=["Chrom", "Site", "coverage", "freqC"])
I need to do some calculations with the βMetβ column, so if it is missing, I will need to calculate it using:
df['Met'] = df['freqC'] * df['coverage']
Is there a way to check if the "Met" column is present in the data frame, and if not add it?
source share