Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,938 questions

51,875 answers

573 users

How to return only the date from DateTime column in pandas with python

1 Answer

0 votes
import pandas as pd

df = pd.DataFrame({"dt_tm": 
    ["2022-01-05 08:09:01", 
     "2022-02-09 09:10:13", 
     "2022-03-12 10:24:17", 
     "2022-04-27 11:37:28"]})

print(pd.to_datetime(df['dt_tm']).dt.date)




'''
run:

0    2022-01-05
1    2022-02-09
2    2022-03-12
3    2022-04-27
Name: dt_tm, dtype: object

'''

 



answered Jul 11, 2022 by avibootz
...