📌  相关文章
📜  如何在 Pandas 中用 0 替换数据框的对角线 - Python 代码示例

📅  最后修改于: 2022-03-11 14:47:22.348000             🧑  作者: Mango

代码示例1
import pandas as pd 
import numpy as np

df = pd.DataFrame(np.random.randint(1,100, 100).reshape(10, -1))

out = df.where(df.values != np.diag(df),0,df.where(df.values != np.flipud(df).diagonal(0),0,inplace=True))