In the pandas Dataframe of following structure:
mcve_data = alfa alfa_id beta beta_id a,c 7 c,de 8 c,d 7 d,f 9 l,mnk 8 c,d 9 j,k 8 d,e 9 tk,l 8 n,k 11 - I want to run a for-loop in each line reading the values from
key(alfa and beta) andkey_index(alfa_index, beta_index). - If the values in the
keyis more than3in length or if any values are more than 1 character long. I want both thekey-valuesandkey-indexto convert to period..
Final expected output:
alfa alfa_id beta beta_id a,c 7 . . c,d 7 d,f 9 . . c,d 9 j,k 8 d,e 9 . . n,k 11 I wanted to write a function something like (but it hasn't worked properly):
def check_and_convert(mcve_data): labels = (l, l + id) for l in mcve_data.columns.values def convert(lines): for l,id in labels: if len(l) > 3: l = '.' id = '.' return l, id write this back to the file. Any suggestions,