def pd_fill_diagonal(df, value):
    idces = df.index.intersection(df.columns)
stacked = df.stack(dropna=False)
stacked.update(pd.Series(value, index=pd.MultiIndex.from_arrays([idces,
    idces])))
df.loc[:, :] = stacked.unstack()
Set values on the diagonal of pandas.DataFrame