0

First I have dataframe as below.

date time name type count
C:\Users\xxx\EK000059.AVI 01:00-01:59 \01\EK000059.AVI Cat 1
C:\Users\xxx\EK000264.AVI 05:00-05:59 \05\EK000264.AVI Cat 1
C:\Users\xxx\EK000495.AVI 07:00-07:59 \07\EK000495.AVI Cat 2
C:\Users\xxx\EK000650.AVI 07:00-07:59 \07\EK000650.AVI Dog 1

I'd like to convert 'date' column to modification time (getmtime) of video files.

for example : date column from C:\Users\xxx\EK000650.AVI to 2022/05/31 and another column same as original condition.

Please recommend and supporting me. Thank you very much.

Kukkik
  • 101
  • 8
  • Something like `df["date"] = df["date"].apply(lambda x: os.path.getmtime(x))` Eventually, use `pd.to_datetime` if you want datetime format see https://www.geeksforgeeks.org/python-os-path-getmtime-method/ https://pandas.pydata.org/docs/reference/api/pandas.to_datetime.html – sslloo Jul 05 '22 at 10:22
  • @sslloo Thank you very much for supporting me. Now I can got example time no. is 1656498242.8203564. Do you recommend me to use `pd.to_datetime` right? How to input this code to continous from `df["date"] = df["date"].apply(lambda x: os.path.getmtime(x))` please recommend to me. – Kukkik Jul 05 '22 at 16:14
  • 1656498242.8203564. seems an absolut timestamp (time in seconds since the reference, 01-01-1970 I think), you can use https://stackoverflow.com/questions/12400256/converting-epoch-time-into-the-datetime – sslloo Jul 05 '22 at 16:24
  • @sslloo I have been used `datetime.datetime.fromtimestamp` in general code and it's work. But I never use this code with pandas dataframe. please recommend to me If I 'd like to change `df["date"]` to date (example 2022/05/31). – Kukkik Jul 05 '22 at 16:33
  • @sslloo I try to use `df["date"] = df["date"].apply(lambda x : os.path.getmtime(x))` and then I use `df["date"] = df["date"].apply(lambda x : datetime.datetime.fromtimestamp(x).strftime('%Y-%m-%d %H:%M'))` output show 2022-06-29 17:24 but It's show only 1 row. I want to show every row. Please supporting me. – Kukkik Jul 05 '22 at 16:43

0 Answers0