I use the following pandas expression
df = df[df.columns[~df.columns.str.contains('Unnamed:')]]
to drop columns that contain Unnamed. I got this one from here Remove Unnamed columns in pandas dataframe
For some reason, in some cases, this line causes an explosion of columns e.g
df shape in (2000, 1451)
after dropping Unnamed (2000, 3851)
in particular, it seems like it causes an explosion in case some columns have the same name e.g duplicates.
Anyone knows why this happens and how to avoid it?
How do I drop columns that have certain substring in duplicate-name-allowed case? Thanks