There are very, very many operations on the processing of time this property in pandas. You can refer to the following links:
Pandas
And this article on one of the people may be more unfamiliar to explain the method. I will upload the rest.
The application scenario is this: given a dataset, the data set has a user's registered account time (year-month-day), as shown in the following figure format.
If we want to convert the user account registration time to a specific number of days, we can use the following code.
Import pandas as PD
td=data[' User_reg_tm ']
time=pd.to_datetime (TD)
Start=pd.datetime (2016,4,16)
Day=start-time
Finally, insert the number of days into the original table
data[' Day ']=day
—————————————————————————————— Split Line ——————————————————
Let's say a few details about creating a time.
DATE=PD. Series ([' 2016411 '])
pd.to_datetime (date)
This creates a time value of 2016-4-11.
Here is a detail, is the time format in the string, if there is no separation between year and month, pandas will automatically use-number separate, if you want to manually separate, for example
DATE=PD. Series ([' 2016-4-11 '])
This can also be, or use/number. Note, however, that you can only use-or/to separate and not use anything else.
Sometimes we need information that is sometimes minutes and seconds.
DATE=PD. Series ([' 2016-4-11 12:12:12 '])
Finally, let's say the next question, how do we take the "days" alone after the number of days I get?
Very simple, with. Days to visit.
For series type, use Data.dt.days
For Timedelta types, direct access to Data.days is available.
For example:
Because data[' Day ' is series type
data[' Day '].dt.days
Because day is a timedelta type of day.days
___________________________________________________________________________
Update: Time to process the next link click Open link