1

enter image description here See the attached screenshot. I want to delete all the rows which contain entries from 'Unnamed' column. i know that the column can be removed by data.drop(data.columns[27], axis=1, inplace=True) but it wont delete the entire rows with it

import pandas as pd
import numpy as np

data = pd.read_csv('/home/syed/ML-Notebook/FL-P1/DATASET_FRAUDE.csv',
                 engine='python',
                 encoding=('latin1'),
                 parse_dates=['FECHA_SINIESTRO','FECHA_INI_VIGENCIA','FECHA_FIN_VIGENCIA','FECHA_DENUNCIO'])


#data.drop(data.columns[27], axis=1, inplace=True)

print(data.info())

2 Answers2

0
df = df[df['Unnamed: 27'].astype(str).map(len) >0]
df

Drop Column:

df = df.loc[:, ~df.columns.str.contains('^Unnamed')]
AtanuCSE
  • 8,832
  • 14
  • 74
  • 112
0

To delete rows macthing a condition you can do:

df = df.drop(df[df.column_name == 'Unnamed'].index)

However this question should be helpfull: Deleting DataFrame row in Pandas based on column value

Pablompg
  • 699
  • 4
  • 8