How to reshape DataFrame after negative value removal?

Hi everyone, I am facing a problem while reshaping a Pandas DataFrame after removing negative values. I have a DataFrame containing several rows and columns, some of which contain negative values. I have used the ‘mask’ function in Pandas to replace all negative values with zero. Now, I want to reshape the DataFrame into a square matrix, but I am not able to figure out the correct method to do so. Therefore, I am seeking your assistance to find an efficient and accurate way to reshape the DataFrame after removing negative values.

I would appreciate any guidance or examples of correct code that can help me to solve this problem.

Hey @nimrah , I have a solution to your query. You can use the NumPy sqrt function to calculate the size of the square and the iloc function to remove any excess values that cannot fit in the square. Let me show you below: