How to remove an unnamed column and remove index while exporting a file?

1.2K    Asked by GayatriJaiteley in Data Science , Asked on Nov 30, 2019
Answered by Gayatri Jaiteley

For removing unnamed columns, we need to import the dataset and after importing following libraries

import numpy as np

import pandas as pd

df=pd.read_csv('dfairannual.csv')

After importing the dataset, we get an unnamed column as follows:



Now to remove such a column that contains no name, we can try the following code.

df = df.loc[:~df.columns.str.contains('^Unnamed')]

Here, with this code, any columns which contain no names will be successfully removed.



Your Answer

Interviews

Parent Categories