[SOLVED] how to remove certain values from a column in python?

Issue

What happens is that I have this set of data and in the column named Fecha de diagnóstico there are many terms like 00:00:00 that I want to eliminate, do you know any method with which I can eliminate all those terms?

Don’t worry, don’t pay attention to the rest, it’s in Spanish.

I tried this

ruta.drop(ruta.loc[ruta['Fecha de diagnóstico']=='00:00:00'].index, inplace=True)

but it doesn’t seem to work

this is i have

%matplotlib inline 
import matplotlib.pyplot as plt 
import numpy as np
import pandas as pd

ruta = pd.read_csv('/content/drive/MyDrive/datos punto 6/Casos_positivos_de_Covid-19_en_el_departamento_de_Antioquia.csv')
cambio = ruta.drop(['fecha reporte web','Fecha de notificación','Código DIVIPOLA departamento','Nombre departamento','Código DIVIPOLA municipio','Unidad de medida de edad','Código ISO del país','Nombre del país','Recuperado','Fecha de inicio de síntomas','Fecha de muerte','Fecha de recuperación','Tipo de recuperación','Pertenencia étnica','Nombre del grupo étnico','Ubicación del caso','Estado','Tipo de contagio'], axis=1)

Solution

If you really have datetime type, keep only the date while keeping the type using:

df['col'] = df['col'].dt.date

Answered By – mozway

Answer Checked By – Marie Seifert (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *