I have to load excel file with few column to pandas data frame. In That Excel file some times data use come with column names "Unnamed 1" ,"Unnamed 2", "Unnamed 3" . I want to delete all the columns where column names start with "Unnamed" . How to do this ? Suppose my data frame name is df .
Asked
Active
Viewed 167 times
1
-
1do you save CSV files through pandas? – Kevin Choi Oct 28 '20 at 08:38
-
Yes will save to CSV . Before that I want to drop the columns with column name starting with "Unnamed" . – Gyanaranjan Nayak Oct 28 '20 at 08:40
1 Answers
1
The easiest way to use this with regex is:
df.drop(list(df.filter(regex = 'Unnamed')), axis = 1, inplace = True)

Rohit Kewalramani
- 408
- 5
- 15