Please take a look at this little snippet of code and explicate on whether there are an efficiency enhancements that you'd make for it. It standards a row of a pandas.DataFrame by adding zeros to it so that the total length of the datum is the same as the longest datum in the column
Sample "solubility.csv" file for testing
SMILES,Solubility
[Br-].CCCCCCCCCCCCCCCCCC[N+](C)(C)C,-3.6161271205000003
O=C1Nc2cccc3cccc1c23,-3.2547670983
[Zn++].CC(c1ccccc1)c2cc(C(C)c3ccccc3)c(O)c(c2)C([O-])=O.CC(c4ccccc4)c5cc(C(C)c6ccccc6)c(O)c(c5)C([O-])=O,-3.9244090954
C1OC1CN(CC2CO2)c3ccc(Cc4ccc(cc4)N(CC5CO5)CC6CO6)cc3,-4.6620645831
def generate_standard():
dataframe = pd.read_csv('solubility.csv', usecols = ['SMILES','Solubility'])
dataframe['standard'],longest = '',''
for _ in dataframe['SMILES']:
if len(str(_)) > len(longest):
longest = str(_)
continue
# index,row in dataframe
for index,row in dataframe.iterrows():
# datum from column called 'SMILES'
smi = row['SMILES']
# zeros = to difference between longest datum and current datum
zeros = (0 for x in range(len(longest) - len(str(smi))))
# makes the zeros into type str
zeros_as_str = ''.join(str(x) for x in zeros)
# concatenate the two str
std = str(smi) + zeros_as_str
# and place it in a new column called standard at the current index
dataframe.at[index,'standard'] = std
return dataframe,longest
longest
come from in your snippet? Add more context with a minimal and testable dataframe fragment \$\endgroup\$ – RomanPerekhrest Oct 31 '19 at 5:47