Here is a sample csv:
| Header A | | Unnamed: 1 | Header D |
|-----------|------|------------|-----------|
| a1 | b1 | c1 | d1 |
| a2 | b2 | c2 | d2 |
If I import it with pandas.read_csv
, it turns into this:
Header A Unnamed: 1 Unnamed: 1.1 Header D
0 a1 b1 c1 d1
1 a2 b2 c2 d2
My goal is dropping all the columns with empty headers, in this case the second column, but I cannot use the assigned column names by pandas to filter them, because there might also be non-empty columns starting with Unnamed
, like the third column in the example.
Columns are not known before hand, so I do not have any control over them.
I have tried the following args with read_csv
, but have not had any luck with them:
prefix
: it just does not work!usecols
: Empty headers already have a name when they are passed tousecols
, which makes it unusable to me.
I have looked at some other answers on SO, like the ones below, but none of them cover my case: