Time formatting implementation in python data cleaning
1. String to time
from datetime import datetime t = 'November 11, 2020 15:04:41' time = (t,'%Y year%m month%d day%H:%M:%S') print(time) # Results : 2020-11-11 15:04:41 t1 = '2020-11-11 15:04:41' time1 = (t1,'%Y-%m-%d %H:%M:%S') print(time1) #Results: 2020-11-11 15:04:41 t2 = 'November 11, 2020' time2 = (t2,'%Y year%m month%d day') print(t2) #in the end 2020surname Nian11moon11date
String to time: using the **(str,t)** method
- str: the string to be converted
- t: convert the format: see the table below (for this method, it is important to ensure that the format of t is exactly the same as str)
2. Time to String
from datetime import datetime t2 = 'November 11, 2020' time2 = (t2,'%Y year%m month%d day') print((time2,'%Y-%m-%d %H:%M:%S'))# in the end:2020-11-11 00:00:00
Time to string: use **(time,t)** method
- time: the time required for the conversion
- t: conversion format: see table below (this method, when the precision of the time is not as high as t, replaces it with 0)
3. Interchangeable timestamps
import time # Convert format strings to timestamps a = "2020-11-11 15:04:41" s = ((a,"%Y-%m-%d %H:%M:%S")) print(s) t = (s) print(('%Y-%m-%d %H:%M:%S',t)) # Results # 1605078281.0 # 2020-11-11 15:04:41
- Time to timestamp: ()
- Time stamp to time: ()
The time-date formatting symbols in the
- %y Two-digit year indication (00-99)
- %Y Four-digit year indication (000-9999)
- %m Month (01-12)
- %d Day of the month (0-31)
- %H 24-hour clock hours (0-23)
- %I 12-hour hours (01-12)
- %M minutes (00=59)
- %S seconds (00-59)
- %a Local simplified weekly name
- %A Local full week name
- %b Local simplified name of the month
- %B Local full month name
- %c Local corresponding date representation and time representation
- %j Day of the year (001-366)
- %p Local. or . Equivalents of
- %U Number of weeks in a year (00-53) Sunday is the start of the week
- %w Week (0-6), Sunday is the start of the week
- %W Number of weeks in a year (00-53) Monday is the start of the week
- %x Local representation of the corresponding date
- %X Local corresponding time representation
- %Z Name of the current time zone
- %% % sign itself
to this article on python data cleaning in the time formatting implementation of the article is introduced to this, more related python data cleaning time formatting content, please search for my previous articles or continue to browse the following related articles I hope you will support me in the future more!
Related articles
Python Calling the API to Send Mail
This article mainly introduces the Python call API to send mail method, to help you better understand and learn to use python, interested parties can understand the following2021-03-03Python Finding Algorithm Implementation of the Fold-and-Half Finding Algorithm
This article introduces the Python lookup algorithm to find the realization of the algorithm, the text of the sample code through the introduction of the very detailed, for everyone's learning or work has a certain reference learning value, the need for friends below with the editorial to learn together!2021-04-04Django framework of routing usage
This article introduces the Django framework of the use of routing, the text through the sample code is very detailed. For everyone's learning or work has a certain reference value, need friends can refer to the following2022-06-06Sample code for python implementation of self-power numbers
This article introduces the python realization of the power of the number of sample code, the text of the sample code through the introduction of the very detailed, for everyone to learn or work with certain reference to the learning value of friends who need the following with the editor to learn together2021-03-03Python implementation to find the intersection of two csv files
This article introduces the Python implementation of the intersection of two csv file method, involving Python for csv file reading, traversal, judgment and other related skills, you can refer to the next!2017-09-09Invalid solution for Python's selenium module using find_element_by_id
This article introduces the Python selenium module using find_element_by_id invalid solution, find_element_by_id invalid may be because of the version of the problem, and the 4.5.0 version does not support the positioning of the page object find_element_by_id method, the previous version of support for these for element positioning, need friends can refer to the following2023-12-12Python Chinese vertical display method
This article introduces the Python Chinese vertical display method, can be realized Python Chinese vertical output display function, with some reference value, need friends can refer to the following2015-07-07Summary of Pycharm's inability to debug issues
Today I'd like to share with you a summary of Pycharm can not debug the problem, has a good reference value, I hope to help you. Together follow the editor over to see it2019-01-01python implementation of cell phone automatic dialing method (call stress test)
Today I would like to share a python for you to realize the method of automatic dialing of cell phones (call stress test), has a good reference value, I hope to help you. Together follow the editor over to see it2019-08-08python to achieve across the excel worksheet sheet between the copy method
Today I'd like to share a python to achieve across excel worksheet sheet between the copy method, has a good reference value, I hope to help you. Together follow the editor over to see it2018-05-05