Using Pandas to manage DocTypes

I want to use Pandas to manage DocTypes.
The idea is to start with my data in Excel.
Load the Excel files using Pandas.
Convert the dataframe dtypes to DocType json file.
Paste the json into Frappe doctype folder.
Then import the Excel data into Frappe using it’s native import function.
Has anyone done that before and have code to share?

I’ve attempted it before and gave up eventually. The problem is with automatic datatype conversions especially Boolean values. Pandas seems to convert and numerical columns to Float. The import templates has many columns which require Boolean value expressed as either a 0 or 1 and Integer columns. It seems that you cannot avoid these columns from being converted to floats. I just did not have the energy to go through all of the converted columns and change them back to Boolean / Integer.

What precisely do you mean with this?

For the actual data import I plan to use the native tool
https://docs.erpnext.com/docs/user/manual/en/setting-up/data/data-import

This is what I got so far. It’s not great but it gets me 50% there.
I paste this to the fields array in my doctype json file.
Then I run bench migrate.
Finally I manually clean up the details using Desk.

def to_doctype(df):
    import json
    doctype = []
    for it in df.columns:
        doctype.append({
            'fieldname': scrub(it),
            'fieldtype': 'Data',
            'label': it,
        })
    return json.dumps(doctype, indent=4)