I currently have the following data.csv which has a comma delimiter:
name,day Chicken Sandwich,Wednesday Pesto Pasta,Thursday Lettuce, Tomato & Onion Sandwich,Friday Lettuce, Tomato & Onion Pita,Friday Soup,Saturday The parser script is:
import pandas as pd df = pd.read_csv('data.csv', delimiter=',', error_bad_lines=False, index_col=False) print(df.head(5)) The output is:
Skipping line 4: expected 2 fields, saw 3 Skipping line 5: expected 2 fields, saw 3 name day 0 Chicken Sandwich Wednesday 1 Pesto Pasta Thursday 2 Soup Saturday How do I handle the case Lettuce, Tomato & Onion Sandwich. Each item should be separated by , but it's possible that an item has a comma in it followed by a space. The desired output is:
name day 0 Chicken Sandwich Wednesday 1 Pesto Pasta Thursday 2 Lettuce, Tomato & Onion Sandwich Friday 3 Lettuce, Tomato & Onion Pita Friday 4 Soup Saturday