I am trying to iterate through each row of a Dataframe. However, using row on Column B (a comma separated field) is splitting this into single characters.
Column A | Column B |
---|---|
pet. | dog,cat |
The code I’m using:
for index, row in df.iterrows():
A1 = row['Column A']
A2 = row['Column B']
print(A2)
A3 = add_units['Column A'].str.split(',').tolist()
A4 = list(A3)
A5 = json.dumps(A4)
print(A5)
I have tried list and json dumps and the format looks correct after the print.But then I can’t iterate and get the error list index out of range.