pandas data analysis, look at this project summary is enough (four: time series)

Original Address: https: //www.kesci.com/home/project/5c418c295c4cef002c33940d/code Note: The code is written on the Pycharm. Note : This section uses data and before different, no longer is the National Bureau of Statistics.


Time series # 10

import pandasas pd

import matplotlib.pyplot as plt

# %matplotlib inline

Note: Here explain the last line: % matplotlib inline .

With an IDE such as python or pycharm spyder, this place will be an error display is invalid syntax (invalid syntax), because pycharm I used, so it is commented out.

% Matplotlib jupyter notebook is in use or jupyter qtconsole time, will be frequently used, the specific role is when you call the plot function plot matplotlib.pyplot of () plotting or generated when a figure canvas, can be directly your python console which generate an image.

In pycharm, the image may be generated by plt.show ().

df_date = pd.read_csv("results.csv")

print (df_date.shape) # is a two-dimensional data iede, the number of output rows and columns

df_date.head()

# 10.1 configuration time series feature

# Converts a string time is the time mode datetime

# pd.to_datetime(data, format, errors)

date type print (df_date.dtypes) # output to object

df_date['date'] = pd.to_datetime(df_date['date'])

print (df_date.dtypes) # date type of the output is datetime64 [ns]

# Begin construction of a new time series

# Each of the following characteristics resulting in a new column

df_date [ 'year'] = df_date [ 'date']. dt.year # configured characterized Year 'year'

df_date [ 'month'] = df_date [ 'date']. dt.month # configured 'month' wherein month

df_date [ 'day'] = df_date [ 'date']. dt.day # configured 'day' day parts wherein

df_date [ 'hour'] = df_date [ 'date']. dt.hour # configured 'hour' h wherein

df_date [ 'minute'] = df_date [ 'date']. dt.minute # configured characterized minutes 'minute'

df_date [ 'second'] = df_date [ 'date']. dt.second # configured characterized in seconds 'second'

df_date [ 'week'] = df_date [ 'date']. dt.week # configured 'week' wherein several weeks

df_date [ 'weekday'] = df_date [ 'date']. dt.weekday +1 # configured 'weekday' wherein week

print(df_date.columns)

df_date.head()

Reproduced in: https: //www.jianshu.com/p/d09ef1f1f4f5

Guess you like

Origin blog.csdn.net/weixin_34061482/article/details/91121768