I have a dataframe:
Isolate1 Isolate2 Isolate3 Isolate4 2 NaN NaN AGTCTA AGT 5 NaN GC NaN NaN And want to replace the NaN values in the Isolate1 column with dashes, one dash for each letter in the non NaN values from the other columns (or the maximum number if other column has other different value), ending in something like these:
Isolate1 Isolate2 Isolate3 Isolate4 2 ------ NaN AGTCTA AGT 5 -- GC NaN NaN I have tried the following:
index_sizes_to_replace = {} for row in df.itertuples(): indel_sizes = [] #0 pos is index for i, value in enumerate(row[1:]): if pd.notnull(value): indel_sizes.append((i, len(value))) max_size = max([size for i, size in indel_sizes]) index_sizes_to_replace[row[0]]= max_size Now I have the number of dashes to replace the NaN values, but dont know how to do the filling, tried this:
for index, size in index_sizes_to_replace.iteritems(): df.iloc[index].fillna("-"*size, inplace=True) But didnt work, any suggestion?