(Oct-26-2019, 04:51 PM)snippsat Wrote:(Oct-26-2019, 02:14 PM)karlito Wrote: I want to drop rows that doesnt start/look like a dateOk,is better if you post a sample of csv file and not image.
Can not use data from a image to test with.
>>> import pandas as pd >>> df = pd.DataFrame({'date': ['12.06.2017', '2003', '114999999', '20.06.2017', '2.08.2018', '554777777'],'value': range(6)}) >>> df date value 0 12.06.2017 0 1 2003 1 2 114999999 2 3 20.06.2017 3 4 2.08.2018 4 5 554777777 5 # Make NaT of row to be dropped >>> pd.to_datetime(df['date'], format='%d.%m.%Y', errors='coerce') 0 2017-06-12 1 NaT 2 NaT 3 2017-06-20 4 2018-08-02 5 NaT Name: date, dtype: datetime64[ns] # Apply >>> df['date'] = pd.to_datetime(df['date'], format='%d.%m.%Y', errors='coerce') >>> df = df.dropna() >>> df date value 0 2017-06-12 0 3 2017-06-20 3 4 2018-08-02 4 # Turn date around to original format if that's needed >>> df['date'] = df['date'].dt.strftime('%d.%m.%Y') >>> df date value 0 12.06.2017 0 3 20.06.2017 3 4 02.08.2018 4
Hi Snippsat,
Thks for your help but I tried it and it doesn't work
link : error
import pandas as pd df = pd.DataFrame({0: ['09.05.2017 13:56', '1494331179', '1494331625', '09.05.2017 14:11', '944006550', '03.07.2017 16:50'],1: range(6)}) df 0 1 0 09.05.2017 13:56 0 1 1494331179 1 2 1494331625 2 3 09.05.2017 14:11 3 4 944006550 4 5 03.07.2017 16:50 5