Is there a way to use the python csv module to save a csv which has two columns of the same name?
This is my function
def DictListToCsv(Data, FileName, FieldNames):
with open(FileName, 'w') as f:
writer = csv.DictWriter(f, fieldnames = FieldNames, dialect = 'excel', delimiter=',', lineterminator='\n')
writer.writeheader()
writer.writerows(Data)
Every approach i try would involve at some point having a dictionary with two headers named the same, which is of course not possible
Have you tried using pandas module ? Convert your data into pandas dataframe ("df") and then use :
df.columns=['x','x']
and finally, save it to a csv file :
df.to_csv(r'/home/ishan/Desktop/a.csv',header=True, index=False)
it will work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With