Currently attempting this with Pandas, but if there is a better way I'm all ears. I have a csv file that looks something like this:
column1 | column2 |
---|---|
value | value |
value | value1, value2 |
value | value |
What I would like to do is:
- Check column2 for rows that have more than one value (e.g. "value, value").
- Create a new row with value2 and remove it from it's original row:
column1 | column2 |
---|---|
value | value |
value | value1 |
value | value2 |
value | value |
I'm not sure what is the best way to determine if a cell in column2 has 2 values, maybe something like this:
for i in df.column2:
if "," in i:
But I'm not sure how to capture that row and write it.