I have this CSV:
| A | B |
|---|---|
| 1 | 3 |
| 2 | 4 |
I would like to add a 2 new headers and for each existing row add an empty value for this new column:
| "column1" | col2 | New1 | New 2 |
|---|---|---|---|
| "timestamp" | "N/A" | ||
| "N/A" | "string element" | ||
| 2 | "string" |
The flat CSV is comma separated:
"column1",col2
"timestamp","N/A"
"N/A","string element"
2,"string"
I tried this but it removes all the double quotes and the "N/A" values
import pandas as pd
df = pd.read_csv(fileName)
df["New1"] = ""
outcsv=fileName
df.to_csv(outcsv, index=False)
The output is:
column1,col2,New1
timestamp,
,string element
2,string
but I would need this output:
"column1",col2,New1,New2
"timestamp","N/A",,
"N/A","string element",,
2,"string",,