In my situation, I export a data frame
to a .csv
file via a for loop
. The dataframe for each iteration is being created from a list of dict
. The exported information is correct but of course, for every iteration, headers are displayed in the csv
file.
Here is the code snippet:
f = open("Test" + ".csv", "w+")
for junc in Junctions:
conn = model.connections(Junction = junc) #list(dict)
DF4dictConn = pd.DataFrame(conn) #convert to DF
DF4dictConn['Junction'] = junc # Add a new column
DF4dictConn.set_index('Junction',inplace=True) #set the new column as index
DF4dictConn.to_csv(f,sep=',') #export dataframe for each junction
The output of the .csv
file is shown below:
Is there a way to avoid the repetition of the headers but only display the header once?
Conn: