I have a large CSV file where columns are separated by commas in each case. However, about 5% of the time the first column contains a comma within itself and is denoted this way by the fact that these fields will have quotations around them if they have a comma inside them.
What would be a good way to read in this file such that we don't treat commas as separators whenever they're contained within quotations?
The best way I am thinking of would be to do something complex with a stack or something to see if we're currently within quotations or not but I think there must surely be an easier way. Note: There are never quotations within quotations or any other corner cases beyond this one.
- Apple, 10, 12, ....
- Banana, 5, 10, ...
- "Banana, green", 3, 14, ... (Notice this line has a comma in it but it has quotations to indicate this)*
I would want to read in this last line into a variable as "Banana, green" rather than the default behavior which would read in banana and green as separate variables.