Dec-27-2022, 07:51 PM
(Dec-27-2022, 07:09 PM)deanhystad Wrote: Looks like you'll have to write the file yourself.
import pandas as pd odd_stuff = pd.DataFrame([[1, '1', 'one', None, ''], [2, '2', '', None, None]]) def df_to_csv(dataframe, csv_file, sep=','): """Write dataframe to csv file using special conventions. 1: All values except None are surrounded by double quotes. 2: None will appear as a blank. """ def rowstr(row): """Format row as a str for writing to a csv file""" return sep.join(['' if x is None else f'"{x}"' for x in row]) df_to_csv(odd_stuff, "test.csv", sep='|')test.csv
Output:"1"|"1"|"one"||"" "2"|"2"|""||
Thank you again deanhystad but is this going to to replace None with '' row by row? It seems like that to me but just trying to be sure as I am little confused with use of "row"