'Get the columns where value is changing timeseriesly
My dataframe has more than 200 columns. Sample Dataframe looks like
Date Tkr col1 col2 col3
20210101 APD 20.0 19.0 15.0
20210101 BCD 20.0 19.0 15.0
20210102 APD 19.0 19.0 15.0
20210102 BCD 20.1 19.2 15.0
I'm trying to extract the columns from col1, col2, col3, where values of these columns are changing daily for any Tkr. For example col3 is not changing, for any Tkr on any Date, but the value of col1 is changing for every Tkr & col2 is changing for any one Tkr, so i'm trying to get col1 and col2.
I'm thinking to implement it with groupBy 'Date' & Tkr, but after that, i need help to do this.
Solution 1:[1]
IIUC, you can use nunique:
>>> df.iloc[:, 2:].nunique().loc[lambda x: x > 1].index.tolist()
['col1', 'col2']
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Corralien |
