I have multiple dataframes and I want to filter each of them so that each df only keeps columns consisting of the word "Overall." I have the following for-loop but it doesn't have the same effect as if I do it manually [aka y15 = y15.filter(like='Overall')].
pit_dfs = [y15,y16,y17]
for i in pit_dfs:
i = i.filter(like='Overall')
Replicable example:
y15 = pd.DataFrame({'Col1-Overall': ['a','b','c','d'],
'Col2': ['a','b','c','d'],
'Col3': ['a','b','c','d'],
'Col4': ['a','b','c','d']})
y16 = pd.DataFrame({'Col1-Overall': ['a','b','c','d'],
'Col2': ['a','b','c','d'],
'Col3': ['a','b','c','d'],
'Col4': ['a','b','c','d']})
y17 = pd.DataFrame({'Col1-Overall': ['a','b','c','d'],
'Col2': ['a','b','c','d'],
'Col3': ['a','b','c','d'],
'Col4': ['a','b','c','d']})
Expected output:
y15
+--------------+
| Col1-Overall |
+--------------+
| a |
+--------------+
| b |
+--------------+
| c |
+--------------+
| d |
+--------------+
y16
+--------------+
| Col1-Overall |
+--------------+
| a |
+--------------+
| b |
+--------------+
| c |
+--------------+
| d |
+--------------+
y17
+--------------+
| Col1-Overall |
+--------------+
| a |
+--------------+
| b |
+--------------+
| c |
+--------------+
| d |
+--------------+
I know this is a simple one, but have been looking through Stack for the past hour and can't find a similar example. What am I missing? Thanks!