Answers for "set diagonal values to zero pandas"

1

How to replace both the diagonals of dataframe with 0 in pandas

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))
Posted by: Guest on June-03-2020

Code answers related to "set diagonal values to zero pandas"

Python Answers by Framework

Browse Popular Code Answers by Language