Get rid of columns that do not have headers

Viewed 718

I'm trying to read in a CSV file that has columns without headers. Currently, my solution is

df = pd.read_csv("test.csv")
df = df[[col for col in df.columns if 'Unnamed' not in col]]

This seems a little hacky, and would fail if the file contains columns with the word 'Unnamed' in them. Is there a better way to do this?

2 Answers
Related