I have a CSV file with a group of inputs.
Example:
A B C D
I want to analyze the results and output a CSV file for each row such as:
Yes, there's a simple way to do it. When you create the csv.DictWriter instance being used, just pass it the keyword argument extrasaction='ignore'
—the default value for it is 'raise'
, which is the cause of the ValueError
exception you're getting when you pass it a dictionary with keys not specified in the fieldnames
parameter.
BTW, reading the relevant documentation before asking SO questions is often a worthwhile endeavor—and can often provide answers without further delay.