I am looping through many txt files which have inconsistent data naming practices. I would like to extract a column which contains specific data, however it has a few different names depending on the file, and often a different location within the header column.
So far I have:
if "Var_version1" in df1.columns or 'Var_version2' in df1.columns:
df2 = df1[["Other_var1","Other_var2","Var_version1"]].copy()
The if or loop is correct, but the extraction is a hold over from before I realized the different naming conventions. How do I extract the entire column if the header contains a particular string or an alternate string within its name? (note: the header name may be xxxxVar_version1xxxx, not just Var_verison1) Thank you!