I have a dataframe in Pandas with 729278 rows and 190 columns:
df1:
+----------+----------+----------+---+---+-----+---------+
| RULE_1_2 | RULE_2_2 | RULE_3_2 | … | … | smt | default |
+----------+----------+----------+---+---+-----+---------+
| 0 | 0 | 0 | … | … | 2 | 0 |
| 0 | 2 | 3 | … | … | 3 | 0 |
| 1 | 3 | 0 | … | … | 4 | 1 |
| … | … | … | … | … | … | … |
+----------+----------+----------+---+---+-----+---------+
Trying to exctract all columns containing RULE and column 'default'.
Code:
df2 = df1[df1.filter(regex='RULE'), df1["default"]]
But Python says:
[729278 rows x 1 columns])' is an invalid key
All columns contain int64 type, which confirmed by df1.dtypes
What's wrong with 1 column 'default'? It doesn't appear in datamrame 'df2'. How to fix it?