How to convert pipe delimited to CSV or JSON

Solution 1:

Pandas read_fwf() is for data files where data is in a fixed column. Sometimes they might have a separator as well (usually a pipe character to make the data table easier to read).

You can read a pipe-separated file with readcsv(). Just use the sep='|':

df = pd.read_csv(filename, sep='|')

Now you can insert the data into the mongo collection converting the dataframe to a dict this way:

Customers.insert_many( df.to_dict(orient='records') )