I have a DataFrame which has Date in it, where the dtype of Date is 'OBJECT'. Now, I need the column names of those which don't have the date in them. I have written code for it but at the end the column names are not getting appended into the list. I really don't know why it is not appending. Can anyone help me with this?
df=
Date ab dc
0 12-02-2020 rat iou
1 22-03-2021 dog dio
2 23-07-2020 cat uyi
code:
valid=[]
invaild=[]
d23 = df.dropna()
for col in d23:
if d23[col].dtype == np.object:
for i in d23[col]:
try:
valid.append(pd.Timestamp(i))
except ValueError:
invaild.append(i)
col_name=[]
if valid == []:
col_name.append(col)
print(col_name)
it gives:
['ab']
['dc']
or if I give out of for loop
then it gives empty list
[]
Where am I going wrong? Output looks like:
col_name = ['ab','dc']