I'm looking for some advice on how to split CSV file using Python. I'm new to Python and strugling with finding the easiest way to achieve it.
Here is the simple example that data I'm trying to split:
ID | tags |
---|---|
01 | tag1;tag2;tag3; |
and here is what I would like data to be presented after:
ID | tags |
---|---|
01 | tag1 |
01 | tag2 |
01 | tag3 |
Remark here is that column "tags" can hold the unlimited number of values.
Any advice will be much appreciated.
Thanks
Here is what worked for me. Thanks for the tips.
with open("test.csv", "r") as f:
for line in f:
l = line.split(',')
tags = l[1].split(';')
for t in tags:
print(l[0],t.strip())