"Data analysis using Python" reading notes--tenth chapter time series

Source: Internet
Author: User
Tags time in milliseconds timedelta



The time series is very important. Time series data is an important structured data format. The meaning of the time series depends on the specific application scenario, mainly in the following ways:


    • Time stamp (timestamp), Specific moment
    • Fixed period (period), such as 2015 year
    • Time interval (interval), represented by a start and end timestamp. That is, the period can be a special case of the time interval.
    • Experiment or process time, each point of time is a measure relative to a specific start time. For example, the diameter of the biscuit per second since it was put into the oven.


Pandas provides a standard set of time-series processing tools and data algorithms. This makes it possible to efficiently process very large time series, easily slice/dice, aggregate, resample periodic/irregular time series, and more. That said, most of them are particularly useful for financial and economic data, and they can also be used to analyze server log data.



1. Date and time data types and tools



The Python standard library contains data types that are used for date, time data. And there are calendar features. The datetime, time, and calendar modules are used primarily.


#-*-coding: utf-8-*-
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import datetime as dt
from datetime import datetime

now = datetime.now ()
#datetime Store time in milliseconds
print now, now.year, now.month, now.day, now.microsecond, ‘\ n’
#print datetime (2015,12,17,20,00,01,555555) #Set a time
# datetime.timedelta represents the time difference between two datetime objects
#In other words, the datetime format can be subtracted
delta = datetime (2011,1,7)-datetime (2008,6,24,8,15)
print delta
# 把 NoteThe following is days And seconds
print dt.timedelta (926,56700)
print delta.days
print delta.seconds
#The following is wrong
#print delta.minutes
start = datetime (2011,1,7)
#Parameters are days, seconds, microseconds (microseconds), milliseconds (milliseconds), minutes, hours, weeks
print start + dt.timedelta (1,20,0.5,5,10,10,0)
>>>
2015-12-17 20: 24: 21.829000 2015 12 17 829000 



926 days, 15:45:00
926 days, 15:45:00
926
56700
2011-01-08 10:10:20.005001
[Finished in 0.6s]



The data types in DateTime are:





    • converting strings and datetime to each other


Using the str or Strftime method (passing in a formatted string), the timestamp object in the DateTime object and pandas can be converted to a string:



"Data analysis using Python" reading notes--tenth chapter time series


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.