Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

filter all columns in pandas

In[1]:
import pandas as pd
import numpy as np

df = pd.DataFrame(np.random.rand(10,5))  
corr = df.corr()
corr.shape

Out[1]: (5, 5)
  
###################  

In [2]: corr_triu = corr.where(~np.tril(np.ones(corr.shape)).astype(np.bool))
         corr_triu
Out[2]: 
    0         1         2         3         4
0 NaN  0.228763 -0.276406  0.286771 -0.050825
1 NaN       NaN -0.562459 -0.596057  0.540656
2 NaN       NaN       NaN  0.402752  0.042400
3 NaN       NaN       NaN       NaN -0.642285
4 NaN       NaN       NaN       NaN       NaN

##################

In [3]: corr_triu = corr_triu.stack()
        corr_triu[corr_triu > 0.3]
Out[3]: 
1  4    0.540656
2  3    0.402752
dtype: float64
Comment

PREVIOUS NEXT
Code Example
Python :: # merge two dictionaries 
Python :: uri beecrowd problem 1047 Game Time with Minutes 
Python :: # to check if the list is empty use len(l) or not 
Python :: how to run 2 async function forever 
Python :: r is.na pandas 
Python :: # filter a list 
Python :: sliding window maximum 
Python :: python nmap api functionality 
Python :: square root in python numpy 
Python :: FizzBuzz in Python Using Conditional Statements 
Python :: turn index back to column 
Python :: print numbers 1 to 10 using recursion in python 
Python :: modern ui python 
Python :: Flatten List in Python Using Without Recursion 
Python :: Code to find maximum number using if else 
Python :: lime python interpretation 
Python :: python 3.9 32 bit 
Python :: how to stop a function from returning none 
Python :: disable chrome console errors selenium 
Python :: linux show output 
Python :: Python NumPy atleast_3d Function Example 
Python :: how to change the color of console output in python to green 
Python :: Python NumPy asanyarray Function Example Scalar to an array 
Python :: python function arguments multiple lines 
Python :: creating a variable bound to a set python 
Python :: find max in for scartch python 
Python :: python fft 
Python :: django view - apiview decorator (urls.py config) 
Python :: if not isinstance multiple values 
Python :: python replace date time column 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =