I need to change a csv file in order to generate a random string value to each row:
This is my code by now:
patients = pd.read_csv("patients.csv")
# updating the column value/data
patients['VALOR_ID'] = patients['VALOR_ID'].str.replace('^(\w+|)',generate_cip())
# writing into the file
patients.to_csv("patients-writer.csv", index=False)
The problem here is that all rows end up having same value.
Any ideas about how to apply generate_cip for each row?
Note:
I need to use replace since row value has this format:
GMCP0200611068|46977549A|81132941070
and I need to change only right before | string part.
For example:
NIF,CIP,FORMAT_ID,VALOR_ID
39999384T,MAMO28374657001,CIP|NASS,XXXXX|2343434|81132941070
39576383R,CACO56874934005,CIP|NASS,XXXXX|39283744|81132941070
My desired output is that XXXXX = generated_cip()
39999384T,MAMO28374657001,CIP|NASS,generated_cip()|2343434|81132941070
39576383R,CACO56874934005,CIP|NASS,generated_cip()|39283744|81132941070
Any ideas?
generate_cip()generates a random value?