I want to write a pandas dataframe to csv. One of the columns of the df has entries which are lists, e.g. [1, 2], [3, 4], ...
When I use df.to_csv(\'output.csv\') and I
I needed commas in my csv file, too. So, I tried to get it using df but in vain. I decided to do the following. I read tap-separated text file, first, and write to a csv file with commas added. Not sure this is what you exactly want, but this way you can have commas in your csv file. Hope it helps.
with open('test.txt', newline = '') as cos:
co_reader = csv.reader(cos, delimiter='\t')
with open('output.csv', 'w', newline='') as csvfile:
cowriter = csv.writer(csvfile, delimiter=',',quotechar='|', quoting=csv.QUOTE_MINIMAL)
for co in cog_reader:
cowriter.writerow(co)